Guest User

Untitled

a guest
Jun 25th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.59 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using UnityEngine.UI;
  4.  
  5. public class CollisionScript : MonoBehaviour {
  6. public int scorePoints;
  7. public int healthAmount;
  8. public Text scoreUI;
  9. public Text health;
  10. public GameObject points;
  11. public GameObject player;
  12. public Camera mainCamera;
  13. public GameObject obstacle;
  14. public GameObject obstacle1;
  15. Vector3 randomPos;
  16. Vector3 randomPos2;
  17. Vector3 randomPos3;
  18. float speed = 1.0f;
  19. float obstacleSpeedX = 1.5f;
  20. float obstacleSpeedY = 1.5f;
  21.  
  22. public void RandomFunction() {
  23. float screenX = Random.Range(2.0f, mainCamera.pixelWidth - 2.0f);
  24. float screenY = Random.Range(2.0f, mainCamera.pixelHeight - 2.0f);
  25. float screenZ = 10.0f;
  26. Vector3 position = mainCamera.ScreenToWorldPoint(new Vector3(screenX, screenY, screenZ));
  27.  
  28. float screenX2 = Random.Range(4.0f, mainCamera.pixelWidth - 4.0f);
  29. float screenY2 = Random.Range(4.0f, mainCamera.pixelHeight - 4.0f);
  30. float screenZ2 = 10.0f;
  31. Vector3 position2 = mainCamera.ScreenToWorldPoint(new Vector3(screenX2, screenY2, screenZ2));
  32.  
  33. float screenX3 = Random.Range(4.0f, mainCamera.pixelWidth - 4.0f);
  34. float screenY3 = Random.Range(4.0f, mainCamera.pixelHeight - 4.0f);
  35. float screenZ3 = 10.0f;
  36. Vector3 position3 = mainCamera.ScreenToWorldPoint(new Vector3(screenX3, screenY3, screenZ3));
  37.  
  38. randomPos2 = position2;
  39.  
  40. if (scorePoints == 1) {
  41. randomPos = position;
  42. randomPos3 = position3;
  43. }
  44. }
  45.  
  46. void Start() {
  47. obstacle.SetActive (false);
  48. obstacle1.SetActive (false);
  49. }
  50.  
  51. void Update() {
  52. if (scorePoints == 5) {
  53. obstacle.SetActive (true);
  54. obstacle.transform.position = randomPos;
  55. } else if (scorePoints == 10) {
  56. obstacle1.SetActive (true);
  57. obstacle1.transform.position = randomPos3;
  58. } else if (scorePoints >= 15) {
  59. obstacle.transform.position += Vector3.right * obstacleSpeedX * Time.deltaTime;
  60. obstacle1.transform.position += Vector3.up * obstacleSpeedY * Time.deltaTime;
  61. }
  62.  
  63. if (obstacle.transform.position.x <= -8.9f) {
  64. obstacleSpeedX = 1.5f;
  65. }
  66.  
  67. if (obstacle.transform.position.x >= 8.9f) {
  68. obstacleSpeedX = -1.5f;
  69. }
  70.  
  71. if (obstacle1.transform.position.y <= -5.0f) {
  72. obstacleSpeedY = 1.5f;
  73. }
  74.  
  75. if (obstacle1.transform.position.y >= 5.0f) {
  76. obstacleSpeedY = -1.5f;
  77. }
  78.  
  79. }
  80.  
  81. public void pointPosition() {
  82. points.transform.position = randomPos2;
  83. }
  84. }
  85.  
  86. using UnityEngine;
  87. using System.Collections;
  88. using UnityEngine.UI;
  89.  
  90. public class LethalCollisionScript : CollisionScript {
  91.  
  92. void OnTriggerEnter2D(Collider2D coll) {
  93. healthAmount -= 1;
  94. player.transform.position = new Vector3(0,0,0);
  95.  
  96. if (healthAmount >= 0) {
  97. health.text = "HEALTH: " + healthAmount;
  98. }
  99.  
  100. if (healthAmount <= -1) {
  101. Application.LoadLevel (0);
  102. }
  103. }
  104. }
  105.  
  106. using UnityEngine;
  107. using System.Collections;
  108.  
  109. public class ObstacleScript : MonoBehaviour {
  110.  
  111. // Update is called once per frame
  112. void Update () {
  113. transform.Rotate (new Vector3 (0, 0, 90) * Time.deltaTime * 2);
  114. }
  115. }
  116.  
  117. using UnityEngine;
  118. using System.Collections;
  119.  
  120. public class PlayerScript : MonoBehaviour {
  121.  
  122. public float speed = 1.0f;
  123. public Camera mainCameraPS;
  124.  
  125. // Use this for initialization
  126. void Start () {
  127.  
  128. }
  129.  
  130. // Update is called once per frame
  131. void Update () {
  132. if (Input.GetKey (KeyCode.LeftArrow)) {
  133. transform.position += Vector3.left * speed * Time.deltaTime;
  134. }
  135. if (Input.GetKey (KeyCode.RightArrow)) {
  136. transform.position += Vector3.right * speed * Time.deltaTime;
  137. }
  138. if (Input.GetKey (KeyCode.UpArrow)) {
  139. transform.position += Vector3.up * speed * Time.deltaTime;
  140. }
  141. if (Input.GetKey (KeyCode.DownArrow)) {
  142. transform.position += Vector3.down * speed * Time.deltaTime;
  143. }
  144.  
  145. if (transform.position.x <= -8.4f)
  146. transform.position = new Vector3 (-8.4f, transform.position.y, transform.position.z);
  147. else if (transform.position.x >= 8.4f)
  148. transform.position = new Vector3(8.4f, transform.position.y, transform.position.z);
  149.  
  150. if (transform.position.y <= -4.6f)
  151. transform.position = new Vector3 (transform.position.x, -4.6f, transform.position.z);
  152. else if (transform.position.y >= 4.6f)
  153. transform.position = new Vector3 (transform.position.x, 4.6f, transform.position.z);
  154. }
  155. }
  156.  
  157. using UnityEngine;
  158. using System.Collections;
  159.  
  160. public class PointCollisionScript : CollisionScript {
  161.  
  162. void OnTriggerEnter2D(Collider2D coll) {
  163.  
  164. RandomFunction ();
  165. pointPosition ();
  166.  
  167. scorePoints += 1;
  168. scoreUI.text = "SCORE: " + scorePoints.ToString ();
  169. }
  170. }
  171.  
  172. public class GameController : MonoBehaviour
  173. {
  174. public GameObject Player;
  175. public UIManager UIManager;
  176.  
  177. void Awake()
  178. {
  179. Player = GameObject.FindWithTag("Player");
  180. UIManager = GameObject.FindObjectOfType<UIManager>();
  181. }
  182. }
  183.  
  184. public class Some_of_Game_Scripts : MonoBehaviour
  185. {
  186. GameController gameController;
  187. UIManager uiManager;
  188.  
  189. void Start()
  190. {
  191. gameController = GameObject.FindWithTag("GameController");
  192. uiManager = gameController.UIManager;
  193. }
  194.  
  195. void Update()
  196. {
  197. uiManager.SetStatusText_Or_Something("Some text");
  198. if (something)
  199. gameController.ResetGame();
  200. }
  201. }
Add Comment
Please, Sign In to add comment