Advertisement
Guest User

Untitled

a guest
Apr 27th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.61 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using UnityEngine.SceneManagement;
  6.  
  7. public class GameManager : MonoBehaviour {
  8. //Objects
  9. public List<GameObject> prefabs = new List<GameObject>();
  10. public int[] tankCount;
  11. private int identificator;
  12. public List<GameObject> objects = new List<GameObject>();
  13.  
  14. //Play checks
  15. private float timer = 3f;
  16. public float Timer {
  17. get{return timer;}
  18. }
  19. private bool isPlaying;
  20. public bool IsPlaying
  21. {
  22. get {return isPlaying;}
  23. }
  24. private bool enterTheBattle;
  25. public bool EnterTheBattle
  26. {
  27. get{ return enterTheBattle;}
  28. }
  29.  
  30. private int blueTeam;
  31. public int BlueTeam
  32. {
  33. get{return blueTeam;}
  34. }
  35. private int redTeam;
  36. public int RedTeam
  37. {
  38. get{return redTeam;}
  39. }
  40.  
  41. //UI
  42. public Text timerText;
  43. public GameObject playButton;
  44. public GameObject tankButtons;
  45.  
  46. public bool endBattle;
  47. public GameObject endBattleTable;
  48. public Text text;
  49. private int money;
  50. public GameObject spawn;
  51.  
  52. public GameObject camButton;
  53. public GameObject cam;
  54. private bool cameresActive;
  55. public Camera[] cameras;
  56. private int camS;
  57. void Start()
  58. {
  59. endBattleTable.SetActive(false);
  60. tankCount[0] = PlayerPrefs.GetInt ("Leopard");
  61. tankCount[1] = PlayerPrefs.GetInt ("Artillery");
  62. }
  63.  
  64. public void IdentificationTank(GameObject tmp)
  65. {
  66. objects.Add(tmp);
  67. tmp = null;
  68. }
  69.  
  70. public void CamerasButton()
  71. {
  72. cameresActive = !cameresActive;
  73. }
  74.  
  75. public void CheckTankButton(int i)
  76. {
  77. identificator = i;
  78. }
  79.  
  80. public void AddRed(){ redTeam++; }
  81. public void AddBlue(){ blueTeam++; }
  82.  
  83. public void RemoveRed(){ redTeam--; }
  84. public void RemoveBlue(){ blueTeam--; }
  85.  
  86. public void TankCameras(int count)
  87. {
  88. cameras[camS].enabled = false;
  89. if(camS + count < 0)
  90. camS = objects.Count - 1;
  91. else if(camS + count > objects.Count - 2)
  92. camS = 0;
  93. else
  94. camS += count;
  95.  
  96. cameras[camS].enabled = true;
  97. }
  98.  
  99. // Update is called once per frame
  100. void Update ()
  101. {
  102. cam.SetActive( cameresActive);
  103.  
  104. if(camS > objects.Count - 1)
  105. camS = objects.Count - 1;
  106.  
  107. if(endBattle && endBattleTable.activeSelf == false)EndBattle();
  108.  
  109. if(isPlaying)
  110. camButton.SetActive(true);
  111. else
  112. camButton.SetActive(false);
  113.  
  114. if(!isPlaying && !enterTheBattle && tankCount[identificator] > 0)
  115. {
  116. if(Input.GetKeyDown(KeyCode.Mouse0))
  117. {
  118. RaycastHit hit;
  119. Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
  120. if (Physics.Raycast(ray, out hit, 10000.0f))
  121. {
  122. if(hit.collider.tag == "spawnPoint" && tankCount[identificator] > 0)
  123. {
  124. Instantiate(prefabs[identificator], new Vector3(hit.point.x, hit.point.y + 0.5f, hit.point.z), Quaternion.identity);
  125. tankCount[identificator]--;
  126. }
  127. }
  128. }
  129. }
  130.  
  131. if(timerText.enabled == true)
  132. timerText.text = "Time to battle: " + timer.ToString("0 sec.");
  133.  
  134. if(enterTheBattle)
  135. {
  136. if(timer > 0)
  137. timer -= Time.deltaTime;
  138. else
  139. {
  140. tankButtons.SetActive(false);
  141. timerText.enabled = false;
  142. playButton.SetActive(false);
  143. isPlaying = true;
  144. enterTheBattle = false;
  145. }
  146. }
  147. }
  148.  
  149. public void MenuButton()
  150. {
  151. PlayerPrefs.SetInt("AddMoney", money);
  152. SceneManager.LoadScene("Menu");
  153. }
  154.  
  155. public void EndBattle()
  156. {
  157. Time.timeScale = 0;
  158. endBattleTable.SetActive(true);
  159. if(blueTeam > 0)
  160. {
  161. text.text = "Blue team is win!";
  162. money = 50;
  163. }
  164. else
  165. {
  166. text.text = "Red team is win!";
  167. money = 200;
  168. }
  169. }
  170.  
  171. public void PlayButton()
  172. {
  173. Time.timeScale = 1;
  174. spawn.SetActive(false);
  175. enterTheBattle = true;
  176. }
  177. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement