Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using UnityEngine.SceneManagement;
- public class GameManager : MonoBehaviour {
- //Objects
- public List<GameObject> prefabs = new List<GameObject>();
- public int[] tankCount;
- private int identificator;
- public List<GameObject> objects = new List<GameObject>();
- //Play checks
- private float timer = 3f;
- public float Timer {
- get{return timer;}
- }
- private bool isPlaying;
- public bool IsPlaying
- {
- get {return isPlaying;}
- }
- private bool enterTheBattle;
- public bool EnterTheBattle
- {
- get{ return enterTheBattle;}
- }
- private int blueTeam;
- public int BlueTeam
- {
- get{return blueTeam;}
- }
- private int redTeam;
- public int RedTeam
- {
- get{return redTeam;}
- }
- //UI
- public Text timerText;
- public GameObject playButton;
- public GameObject tankButtons;
- public bool endBattle;
- public GameObject endBattleTable;
- public Text text;
- private int money;
- public GameObject spawn;
- public GameObject camButton;
- public GameObject cam;
- private bool cameresActive;
- public Camera[] cameras;
- private int camS;
- void Start()
- {
- endBattleTable.SetActive(false);
- tankCount[0] = PlayerPrefs.GetInt ("Leopard");
- tankCount[1] = PlayerPrefs.GetInt ("Artillery");
- }
- public void IdentificationTank(GameObject tmp)
- {
- objects.Add(tmp);
- tmp = null;
- }
- public void CamerasButton()
- {
- cameresActive = !cameresActive;
- }
- public void CheckTankButton(int i)
- {
- identificator = i;
- }
- public void AddRed(){ redTeam++; }
- public void AddBlue(){ blueTeam++; }
- public void RemoveRed(){ redTeam--; }
- public void RemoveBlue(){ blueTeam--; }
- public void TankCameras(int count)
- {
- cameras[camS].enabled = false;
- if(camS + count < 0)
- camS = objects.Count - 1;
- else if(camS + count > objects.Count - 2)
- camS = 0;
- else
- camS += count;
- cameras[camS].enabled = true;
- }
- // Update is called once per frame
- void Update ()
- {
- cam.SetActive( cameresActive);
- if(camS > objects.Count - 1)
- camS = objects.Count - 1;
- if(endBattle && endBattleTable.activeSelf == false)EndBattle();
- if(isPlaying)
- camButton.SetActive(true);
- else
- camButton.SetActive(false);
- if(!isPlaying && !enterTheBattle && tankCount[identificator] > 0)
- {
- if(Input.GetKeyDown(KeyCode.Mouse0))
- {
- RaycastHit hit;
- Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
- if (Physics.Raycast(ray, out hit, 10000.0f))
- {
- if(hit.collider.tag == "spawnPoint" && tankCount[identificator] > 0)
- {
- Instantiate(prefabs[identificator], new Vector3(hit.point.x, hit.point.y + 0.5f, hit.point.z), Quaternion.identity);
- tankCount[identificator]--;
- }
- }
- }
- }
- if(timerText.enabled == true)
- timerText.text = "Time to battle: " + timer.ToString("0 sec.");
- if(enterTheBattle)
- {
- if(timer > 0)
- timer -= Time.deltaTime;
- else
- {
- tankButtons.SetActive(false);
- timerText.enabled = false;
- playButton.SetActive(false);
- isPlaying = true;
- enterTheBattle = false;
- }
- }
- }
- public void MenuButton()
- {
- PlayerPrefs.SetInt("AddMoney", money);
- SceneManager.LoadScene("Menu");
- }
- public void EndBattle()
- {
- Time.timeScale = 0;
- endBattleTable.SetActive(true);
- if(blueTeam > 0)
- {
- text.text = "Blue team is win!";
- money = 50;
- }
- else
- {
- text.text = "Red team is win!";
- money = 200;
- }
- }
- public void PlayButton()
- {
- Time.timeScale = 1;
- spawn.SetActive(false);
- enterTheBattle = true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement