Advertisement
Guest User

Untitled

a guest
Mar 31st, 2015
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.22 KB | None | 0 0
  1. public void GameOver(bool win)
  2. {gameOver = true;
  3. restartText.text = "Press 'R' to Restart";
  4. if (win == true) {gameOverText.text = "You Win!";}
  5. if (win == false) {gameOverText.text = "You Lose!";}
  6.  
  7. player.GetComponent<Rigidbody>().useGravity = false;
  8. player.GetComponent<Rigidbody>().velocity = new Vector3 (0, 0, 0);
  9.  
  10. if (player.GetComponent<Rigidbody>() == null)
  11. {Debug.Log ("Could not find Player Rigidbody for GameOver method");}
  12. }
  13.  
  14. if (gameOver)
  15. {if (GameOver (win: true))
  16. {gameOverText.text = "You Win!";}
  17. if (GameOver (win: false))
  18. {gameOverText.text = "You Lose!"}
  19.  
  20. public void GameOver(bool win)
  21. {gameOver = true;}
  22.  
  23. public class GameController : MonoBehaviour
  24.  
  25. {public GUIText scoreText;
  26. public GUIText gameOverText;
  27. public GUIText restartText;
  28. public GameObject player;
  29.  
  30. private bool gameOver;
  31. private int score;
  32.  
  33. void Start ()
  34. {gameOver = false;
  35. gameOverText.text = "";
  36. restartText.text = "";
  37.  
  38. score = 0;
  39. UpdateScore ();}
  40.  
  41. void Update ()
  42. {if (gameOver)
  43. {if (Input.GetKeyDown (KeyCode.R))
  44. {Application.LoadLevel (Application.loadedLevel);}
  45. }
  46. }
  47.  
  48. public void AddScore( int pointVal)
  49. {score += pointVal;
  50. UpdateScore ();}
  51.  
  52. void UpdateScore ()
  53. {scoreText.text = "Score: " + score;}
  54.  
  55. public void GameOver(bool win)
  56. {gameOver = true;
  57. restartText.text = "Press 'R' to Restart";
  58. if (win == true) {gameOverText.text = "You Win!";}
  59. if (win == false) {gameOverText.text = "You Lose!";}
  60.  
  61. player.GetComponent<Rigidbody>().useGravity = false;
  62. player.GetComponent<Rigidbody>().velocity = new Vector3 (0, 0, 0);
  63.  
  64. if (player.GetComponent<Rigidbody>() == null)
  65. {Debug.Log ("Could not find Player Rigidbody for GameOver method");}
  66. }
  67. }
  68.  
  69. public class PlayerController : MonoBehaviour
  70. {public float speed;
  71. private GameController gameController;
  72.  
  73. void Start()
  74. {GameObject gameContObj = GameObject.FindWithTag ("GameController");
  75. if (gameContObj != null)
  76. {gameController = gameContObj.GetComponent <GameController>();}
  77. if (gameContObj == null)
  78. {Debug.Log ("Cannot find 'GameController' script");}
  79. }
  80.  
  81. void Update ()
  82. {float moveHorizontal = Input.GetAxis ("Horizontal");
  83. float moveVertical = Input.GetAxis ("Vertical");
  84. Vector3 playerMovement = new Vector3 (moveHorizontal, moveVertical, 0.0f);
  85. transform.Translate (playerMovement * speed * Time.deltaTime);}
  86.  
  87. void OnTriggerEnter(Collider other)
  88. {if (other.tag == "Obstacle")
  89. {gameController.GameOver (win: false);}
  90. if (other.tag == "End Level")
  91. {gameController.GameOver (win: true);}
  92. if (other.tag == "Pickup") {return;}
  93. }
  94. }
  95.  
  96. public class DestroybyContact : MonoBehaviour
  97. {public int pointValue;
  98. private GameController gameController;
  99.  
  100. void Start()
  101. {GameObject gameContObj = GameObject.FindWithTag ("GameController");
  102. if (gameContObj != null)
  103. {gameController = gameContObj.GetComponent <GameController>();}
  104. if (gameContObj == null)
  105. {Debug.Log ("Cannot find 'GameController' script");}
  106. }
  107.  
  108. void OnTriggerEnter (Collider other)
  109. {if (other.tag == "MainCamera")
  110. {Destroy (gameObject);
  111. gameController.AddScore (pointValue);}
  112. }
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement