Hi All,
I´m trying to do a Moon Landing Game. You control a spacescraft and have to activate different landing pads (depends on how much landing pads are available in the level). The Main Problem I have is accessing other Scripts, maybe someone can help me out here!?
I´ve commented the code so you can get an idea of what I´m trying to do… I have 4 scripts attached (InGameGUI, MainMenuGUI, PlayerControl, LandingPad)
InGameGUI
public class InGameGUI : MonoBehaviour {
int numActivated;
int totalLZ;
public string guiMode = "InGame";
void Update ()
{
if (Input.GetKeyDown ("escape")) // if Escape Key is pressed, switch to Pause State
{
Time.timeScale = 0; // Stop Time
guiMode = "Paused";
Debug.Log ("Paused..");
}
}
public void OnGUI ()
{
if (guiMode == "Paused") // declares GUI Buttons if guiMode = Paused
{
if (GUI.Button (new Rect (Screen.width / 2 - 75, Screen.height / 2 - 20, 150, 30), "Resume Game"))
{
Time.timeScale = 1;
guiMode = "InGame";
Debug.Log ("resume..");
}
if (GUI.Button (new Rect (Screen.width / 2 - 75, Screen.height / 2 + 20, 150, 30), "Quit to Main Menu"))
{
Time.timeScale = 1;
Application.LoadLevel(0);
Debug.Log ("quitting..");
}
}
if (guiMode == "Win") // declares GUI Buttons if guiMode = Win
{
if (GUI.Button (new Rect (Screen.width / 2 - 75, Screen.height / 2 - 20, 150, 30), "Next Level"))
{
Time.timeScale = 1;
Application.LoadLevel(Application.loadedLevel+1);
guiMode = "InGame";
Debug.Log ("next Level..");
}
if (GUI.Button (new Rect (Screen.width / 2 - 75, Screen.height / 2 + 20, 150, 30), "Quit to Main Menu"))
{
Time.timeScale = 1;
Application.LoadLevel(0);
Debug.Log ("quitting..");
}
}
if (guiMode == "Lose") // declares GUI Buttons if guiMode = Lose
{
if (GUI.Button (new Rect (Screen.width / 2 - 75, Screen.height / 2 - 20, 150, 30), "Retry Level"))
{
Time.timeScale = 1;
Application.LoadLevel(Application.loadedLevel);
guiMode = "InGame";
Debug.Log ("retry Level..");
}
if (GUI.Button (new Rect (Screen.width / 2 - 75, Screen.height / 2 + 20, 150, 30), "Quit to Main Menu"))
{
Time.timeScale = 1;
Application.LoadLevel(0);
Debug.Log ("quitting..");
}
}
}
public void LZActivated() // check how many Landing Pads are activated.
{
numActivated++;
if (numActivated == totalLZ) // check if all Landing Pads are activated. If yes, change to Win State
{
Win();
}
Debug.Log ("LZ Activated");
}
public void Win() // declares what happens if GUI Mode is Win
{
Time.timeScale = 0;
guiMode = "Win";
}
public void Lose() // declares what happens if GUI Mode is Lose
{
Time.timeScale = 0;
guiMode = "Lose";
}
}
MainMenuGUI
public class MainMenuGUI : MonoBehaviour {
void OnGUI ()
{
if(GUI.Button(new Rect(Screen.width/2-75,Screen.height/2-20,150,30),"New Game"))
{
Application.LoadLevel(1);
Debug.Log("Starting New Game");
}
if(GUI.Button(new Rect(Screen.width/2-75,Screen.height/2+20,150,30),"Continue Game"))
{
Debug.Log("Continue Game");
}
}
}
PlayerController - The Particle Emitter doesn´t work either, so I´ve commented it out, but that´s another story
public class PlayerController : MonoBehaviour {
// var bottomThruster : ParticleEmitter;
// var topThruster : ParticleEmitter;
// var leftThruster : ParticleEmitter;
// var rightThruster : ParticleEmitter;
public GameObject shipExplosion;
public void Update ()
{
if(Input.GetAxis("Horizontal") > 0) // checking for right arrow key
{
// leftThruster.emit = true;
rigidbody.AddForce(10,0,0);
}
if(Input.GetAxis("Horizontal") < 0) // checking for left arrow key
{
// rightThruster.emit = true;
rigidbody.AddForce(-10,0,0);
}
if(Input.GetAxis("Horizontal") == 0) // checking if no horizontal keys down
{
// rightThruster.emit = false;
// leftThruster.emit = false;
}
if(Input.GetAxis("Vertical") > 0) // checking for up arrow key
{
// bottomThruster.emit = true;
rigidbody.AddForce(0,10,0);
}
if(Input.GetAxis("Vertical") < 0) // checking for down arrow key
{
// topThruster.emit = true;
rigidbody.AddForce(0,-10,0);
}
if(Input.GetAxis("Vertical") == 0) // checking if no vertical keys down
{
// topThruster.emit = false;
// bottomThruster.emit = false;
}
}
public void OnCollisionEnter(Collision collision) // Kill Game Object on Collision if Collision Magnitude higher than 2
{
Debug.Log(collision.relativeVelocity.magnitude);
if (collision.relativeVelocity.magnitude > 2) // Kill Game Object if Collision higher than 2
{
Explode ();
}
else if (collision.gameObject.tag == "LandingPad") // Debug Log if Collision with Landing Pad
{
Debug.Log ("Landed");
}
else if (collision.gameObject.tag == "Asteroid") // Kill Game Object if collision with Tag Asteroid
{
Explode ();
}
}
public void Explode() // Instantiate Ship Explosion
{
Instantiate(shipExplosion, transform.position, transform.rotation);
Destroy(gameObject);
}
}
Landing Pad
public class LandingPad : MonoBehaviour {
public GameObject GuiMode;
public void Start ()
{
GameObject.FindWithTag("GUI").GetComponent<InGameGUI>(); // try to get InGameGUI for every Landing Pad in Scene, so that I can setup Winning Conditions
}
void Update () {
}
public void OnCollisionEnter (Collision Collision)
{
if (Collision.relativeVelocity.magnitude < 2) // if Collision lower than 2, change Color to green
{
transform.renderer.material.color = Color.green;
// GUI.LZActivated();
}
}
}
I would really appreciate if someone could help me out.
THANKS