Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void GameOver(bool win)
- {gameOver = true;
- restartText.text = "Press 'R' to Restart";
- if (win == true) {gameOverText.text = "You Win!";}
- if (win == false) {gameOverText.text = "You Lose!";}
- player.GetComponent<Rigidbody>().useGravity = false;
- player.GetComponent<Rigidbody>().velocity = new Vector3 (0, 0, 0);
- if (player.GetComponent<Rigidbody>() == null)
- {Debug.Log ("Could not find Player Rigidbody for GameOver method");}
- }
- if (gameOver)
- {if (GameOver (win: true))
- {gameOverText.text = "You Win!";}
- if (GameOver (win: false))
- {gameOverText.text = "You Lose!"}
- public void GameOver(bool win)
- {gameOver = true;}
- public class GameController : MonoBehaviour
- {public GUIText scoreText;
- public GUIText gameOverText;
- public GUIText restartText;
- public GameObject player;
- private bool gameOver;
- private int score;
- void Start ()
- {gameOver = false;
- gameOverText.text = "";
- restartText.text = "";
- score = 0;
- UpdateScore ();}
- void Update ()
- {if (gameOver)
- {if (Input.GetKeyDown (KeyCode.R))
- {Application.LoadLevel (Application.loadedLevel);}
- }
- }
- public void AddScore( int pointVal)
- {score += pointVal;
- UpdateScore ();}
- void UpdateScore ()
- {scoreText.text = "Score: " + score;}
- public void GameOver(bool win)
- {gameOver = true;
- restartText.text = "Press 'R' to Restart";
- if (win == true) {gameOverText.text = "You Win!";}
- if (win == false) {gameOverText.text = "You Lose!";}
- player.GetComponent<Rigidbody>().useGravity = false;
- player.GetComponent<Rigidbody>().velocity = new Vector3 (0, 0, 0);
- if (player.GetComponent<Rigidbody>() == null)
- {Debug.Log ("Could not find Player Rigidbody for GameOver method");}
- }
- }
- public class PlayerController : MonoBehaviour
- {public float speed;
- private GameController gameController;
- void Start()
- {GameObject gameContObj = GameObject.FindWithTag ("GameController");
- if (gameContObj != null)
- {gameController = gameContObj.GetComponent <GameController>();}
- if (gameContObj == null)
- {Debug.Log ("Cannot find 'GameController' script");}
- }
- void Update ()
- {float moveHorizontal = Input.GetAxis ("Horizontal");
- float moveVertical = Input.GetAxis ("Vertical");
- Vector3 playerMovement = new Vector3 (moveHorizontal, moveVertical, 0.0f);
- transform.Translate (playerMovement * speed * Time.deltaTime);}
- void OnTriggerEnter(Collider other)
- {if (other.tag == "Obstacle")
- {gameController.GameOver (win: false);}
- if (other.tag == "End Level")
- {gameController.GameOver (win: true);}
- if (other.tag == "Pickup") {return;}
- }
- }
- public class DestroybyContact : MonoBehaviour
- {public int pointValue;
- private GameController gameController;
- void Start()
- {GameObject gameContObj = GameObject.FindWithTag ("GameController");
- if (gameContObj != null)
- {gameController = gameContObj.GetComponent <GameController>();}
- if (gameContObj == null)
- {Debug.Log ("Cannot find 'GameController' script");}
- }
- void OnTriggerEnter (Collider other)
- {if (other.tag == "MainCamera")
- {Destroy (gameObject);
- gameController.AddScore (pointValue);}
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement