using UnityEngine; using System.Collections; public class WaveController : MonoBehaviour { //variables public float killTotal; public float wave; public float spawnRate; private GameObject[] goblinSize; public float waveOneKillGoal; public float waveTwoKillGoal; public float waveThreeKillGoal; public float waveFourKillGoal; public float victoryKillGoal; bool killGoalOne; bool killGoalTwo; bool killGoalThree; bool killGoalFour; bool victory; bool killGoalsMet; public SpawnGoblins goblinSpawning; private float timeSoFar; public float timeComplete; public int currentWave = 1; public AudioClip[] waveSound; public Transform playerChar; public GUISkin customSkin; private int difficulty; // Use this for initialization void Start () { difficulty = PlayerPrefs.GetInt("difficulty"); AudioSource.PlayClipAtPoint(waveSound[0],playerChar.position); //switch the difficulty and based on the difficulty change the kill goals switch(difficulty) { case 0: //leave the settings as they are since they are so easy break; case 1: waveOneKillGoal *= 2; waveTwoKillGoal *= 2; waveThreeKillGoal *= 2; waveFourKillGoal *= 2; victoryKillGoal *= 2; break; case 2: waveOneKillGoal *= 4; waveTwoKillGoal *= 4; waveThreeKillGoal *= 4; waveFourKillGoal *= 4; victoryKillGoal *= 4; break; } } // Update is called once per frame void Update () { //increment our time timeSoFar += Time.deltaTime * 1; //find out how many goblins there are in the world goblinSize = GameObject.FindGameObjectsWithTag("Goblin"); //Wave one met if(killTotal > waveOneKillGoal && !killGoalOne) { AudioSource.PlayClipAtPoint(waveSound[1],playerChar.position); killGoalOne = true; goblinSpawning.spawnRate -= 2.0F; currentWave += 1; } //Wave Two Met if(killTotal > waveTwoKillGoal && !killGoalTwo) { AudioSource.PlayClipAtPoint(waveSound[2],playerChar.position); killGoalTwo = true; goblinSpawning.spawnRate -= 2.0F; currentWave += 1; } //Wave three Met if(killTotal > waveThreeKillGoal && !killGoalThree) { AudioSource.PlayClipAtPoint(waveSound[3],playerChar.position); killGoalThree = true; goblinSpawning.spawnRate -= 2.0F; currentWave += 1; } //Wave Four Met if(killTotal > waveFourKillGoal && !killGoalFour) { AudioSource.PlayClipAtPoint(waveSound[4],playerChar.position); killGoalFour = true; goblinSpawning.spawnRate -= 2.0F; currentWave += 1; } //Wave Four Met if( killTotal > victoryKillGoal && !victory && !killGoalsMet ) { killGoalsMet = true; goblinSpawning.maxGoblins = 0; //currentWave += 1; } if(goblinSize.Length < 1 && killGoalsMet && !victory) { timeComplete = timeSoFar; victory = true; } } void OnGUI() { GUI.skin = customSkin; if(!victory) { ///////////////////////////////// /////Draw the Current Wave/////// ///////////////////////////////// if(currentWave < 5) { GUI.Label(new Rect(Screen.width/2 - 180 ,40,Screen.width/4 ,40) ,"Wave " + currentWave); }else { GUI.Label(new Rect(Screen.width/8 ,Screen.height/2 - 40,Screen.width/8 ,40) ,"Final Wave"); } /////////////////////////////////// ///////Draw timer and kill score/// /////////////////////////////////// GUI.Label(new Rect(Screen.width/8 ,Screen.height/4,Screen.width/8 ,40) ,"Kills :" + Mathf.Round(killTotal).ToString()); GUI.Label(new Rect(Screen.width/8 ,Screen.height/2,Screen.width ,40) ,"Time : Minutes " + (timeSoFar/60).ToString("n0") + "seconds : " + (timeSoFar%60).ToString("n0")); } if(victory) { /////Draw the Time the player completed all waves and their total Kills GUI.Label(new Rect(Screen.width/2 - 80 ,Screen.height/2,Screen.width/4 + 90 ,90) ,"Total Kills - " + Mathf.Round(killTotal).ToString() + ". Completed " + currentWave + " Waves in " + (timeComplete/60).ToString("n0") + " Minutes " + (timeComplete%60).ToString("n2") + "seconds"); //Draw restart and quit buttons for the player if (GUI.Button(new Rect(Screen.width/2 - 40,Screen.height/2 + 50,100,30),"Restart")) { Application.LoadLevel("Pariah Forest"); } if (GUI.Button(new Rect(Screen.width/2 + 60,Screen.height/2 + 50,60,30),"Quit")) { Application.LoadLevel("Pariah Main Menu"); } } } public void AddKill() { killTotal += 1; } public void AddWave() { wave += 1; } }