// Use this for initialization void Start() { #if UNITY_EDITOR GameCore.SetDebugCheck(debugMode); #endif // Find the GUI Controllers if not attached if (InGameGUI == null) { Debug.LogError("<GM> InGameGUI was not initially attached"); InGameGUI = GameObject.Find("InGameGUI"); } if (StartGUI == null) { Debug.LogError("<GM> StartGUI was not initially attached"); StartGUI = GameObject.Find("StartGUI"); } if (GameOverGUI == null) { Debug.LogError("<GM> GameOverGUI was not initially attached"); GameOverGUI = GameObject.Find("GameOverGUI"); } // Set the default state of the game to the Start state ToggleGameState(GameCore.GameState.Start); // Set the default variables for SpawnCore just like the above SpawnCore.ResetSpawnVars(); }
public void StartSpawning() { // Set the spawner to active active = true; spawnCoolDown = false; // Set up the first wave SpawnCore.FirstWave(); }
// Sets positions and other settings void SetGame() { // Set the standard settings for GameCore variables GameCore.ResetGameVars(); // Set the default variables and standard settings for SpawnCore just like the above SpawnCore.ResetSpawnVars(); // Tell player to reset itself PlayerControl.Instance.Reset(); }
public void KillSpawn() { // Broadcast that an enemy has been destroyed this wave SpawnCore.IncrementWaveDestroyed(); // Deactivate the spawned object this.gameObject.renderer.enabled = false; this.gameObject.GetComponent <PolygonCollider2D>().enabled = false; // Return the object to its spawn pool this.transform.parent = spawnPool; // Reset according to enemy type // Activate movement/attack depending on enemy type if (thisEnemy == null) { Debug.LogError("<SpawnObj> Object type is null!"); } if (thisEnemy == SpawnCore.EnemyType.Enemy0) { this.gameObject.GetComponent <FirstEnemy>().Deactivate(); } }
IEnumerator DelayedSpawn(SpawnCore.EnemyType enemyType) { // Don't let spawning back to back continuously spawnCoolDown = true; // Spawn the enemy according to the wishes from above if (enemyType == SpawnCore.EnemyType.Enemy0) { SpawnEnemy0(spawnPool0.GetSpawn()); } else { Debug.LogError("<Spawner> Stupid idiot, that enemy type don't exist"); } // Increment stats SpawnCore.IncreaseSpawnTotals(); // Wait until allowing to spawn again yield return(new WaitForSeconds(SpawnCore.spawnDelay)); // THEN allow spawning again spawnCoolDown = false; }
// Update is called once per frame void Update() { #if UNITY_EDITOR // Spawn an enemey if e key is pressed if (Input.GetKeyDown("e")) { // If not active, don't continue if (!active) { print("<Spawner> Spawner inactive"); return; } // FOR GETTING TIMING BETWEEN SPAWNING ENEMIES if (lastSpawnTime == 0f) { print("Setting first spawn time"); // Set initial lastSpawnTime lastSpawnTime = Time.time; } else { print("Time Between Spawns: " + (Time.time - lastSpawnTime)); // Reassign lastSpawnTime lastSpawnTime = Time.time; } // Increase the amount spawned SpawnCore.IncreaseSpawnTotals(); // Actually spawn the enemy SpawnEnemy0(spawnPool0.GetSpawn()); } // Print spawn statistics if (Input.GetKeyDown("s")) { print("<---- Printing Spawn Statistics ---->"); print("Total Spawned: " + SpawnCore.totalSpawned); print("Current Wave: " + SpawnCore.currentWave); print("This Wave's Goal: " + SpawnCore.thisWave_goal); print("This Wave's Spawned: " + SpawnCore.thisWave_spawned); print("This Wave's Destroyed: " + SpawnCore.thisWave_defeated); print("<-- End Spawn Statistics -->"); } #endif // If the Spawner is active... if (active) { // If not enough spawns have been made to reach this spawn's goals if (SpawnCore.thisWave_defeated < SpawnCore.thisWave_goal) { // If spawn is NOT on cool down, then continue spawning if (!spawnCoolDown) { // Spawn an enemy StartCoroutine(DelayedSpawn(SpawnCore.EnemyType.Enemy0)); } } // end thisWaveGoal != thisWaveSpawn // Else check that the number destroyed == thisWaveGoal else if (SpawnCore.thisWave_goal <= SpawnCore.thisWave_defeated) { // Activate the next wave SpawnCore.NextWave(); print("Current Wave: " + SpawnCore.currentWave); } } }