ltrout

GameManager (I created this for both tanks) WIP

Dec 24th, 2015
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.25 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using UnityEngine.UI;
  4. using PlayerInfo;
  5. using EnemyInfo;
  6.  
  7. namespace Management
  8. {
  9.     public class GameManager : MonoBehaviour
  10.     {
  11.         public static int PlayerScore;
  12.         public static int EnemyScore;
  13.         public Text ScoreText;
  14.         public Text GameText;
  15.         public float StartDelay = 3f;
  16.         public float EndDelay = 3f;
  17.         public GameManager[] Tanks;
  18.  
  19.         PlayerManager PManage;
  20.         EnemyManager EManage;
  21.         WaitForSeconds StartWait;
  22.         WaitForSeconds EndWait;
  23.         GameManager RoundWinner;
  24.         GameManager GameWinner;
  25.         int RoundNumber;
  26.         int Wins;
  27.  
  28.         void Awake ()
  29.         {
  30.             PlayerScore = 0;
  31.             EnemyScore = 0;
  32.         }
  33.  
  34.         public void Start ()
  35.         {
  36.             StartWait = new WaitForSeconds (StartDelay);
  37.             EndWait = new WaitForSeconds (EndDelay);
  38.  
  39.             SpawnTanks ();
  40.  
  41.             StartCoroutine (GameLoop ());
  42.         }
  43.  
  44.         void Update ()
  45.         {
  46.             ScoreText.text = "Round Wins: " + PlayerScore + " - " + EnemyScore;
  47.         }
  48.  
  49.         public void SpawnTanks ()
  50.         {
  51.             PManage.PSpawn ();
  52.             PManage.PSetup ();
  53.             EManage.ESpawn ();
  54.             EManage.ESetup ();
  55.         }
  56.  
  57.         public IEnumerator GameLoop ()
  58.         {
  59.             yield return StartCoroutine (RoundStarting ());
  60.  
  61.             yield return StartCoroutine (RoundPlaying ());
  62.  
  63.             yield return StartCoroutine (RoundEnding ());
  64.  
  65.         }
  66.  
  67.         IEnumerator RoundStarting ()
  68.         {
  69.             ResetAllTanks ();
  70.             DisableTankControl ();
  71.  
  72.             RoundNumber++;
  73.             GameText.text = "ROUND: " + RoundNumber;
  74.  
  75.             yield return StartWait;
  76.         }
  77.  
  78.         IEnumerator RoundPlaying ()
  79.         {
  80.             EnableTankControl ();
  81.  
  82.             GameText.text = string.Empty;
  83.  
  84.             while (!OneTankLeft ())
  85.             {
  86.                 yield return null;
  87.             }
  88.         }
  89.  
  90.         IEnumerator RoundEnding ()
  91.         {
  92.             DisableTankControl ();
  93.  
  94.             RoundWinner = null;
  95.  
  96.             RoundWinner = GetRoundWinner ();
  97.  
  98.             if (RoundWinner != null)
  99.                 RoundWinner.Wins++;
  100.  
  101.             GameWinner = GetGameWinner ();
  102.  
  103.             yield return EndWait;
  104.         }
  105.  
  106.         bool OneTankLeft ()
  107.         {
  108.             int numTanksLeft = 0;
  109.  
  110.             for (int i = 0; i < Tanks.Length; i++)
  111.             {
  112.                 if (Tanks [i].Instance.activeSelf)
  113.                     numTanksLeft++;
  114.             }
  115.         }
  116.  
  117.         GameManager GetRoundWinner ()
  118.         {
  119.  
  120.         }
  121.  
  122.         GameManager GetGameWinner ()
  123.         {
  124.  
  125.         }
  126.  
  127.         void ResetAllTanks ()
  128.         {
  129.  
  130.         }
  131.  
  132.         void EnableTankControl ()
  133.         {
  134.  
  135.         }
  136.  
  137.         void DisableTankControl ()
  138.         {
  139.  
  140.         }
  141.     }
  142. }
Add Comment
Please, Sign In to add comment