I am making a game with multiple waves of enemies. I initiate the new wave of enemies in another script by increasing the waveNumber of this script by 1. To detect this change and run the wave, I have implemented the update() code below. The problem is, despite the waveNumber changing correctly and lastWave not changing from its default value of 0, doWave() is not happening (“wave is happening” never prints). There are no errors in the console. Can anyone shed some light on this odd behavior? I hope this makes sense. Please ask for clarification if it doesn’t!
using UnityEngine;
using System.Collections;
public class Waves : MonoBehaviour {
public int waveNumber;
public int lastWave;
public bool waveInProgress;
void update()
{
if (lastWave != waveNumber)
{
lastWave = waveNumber;
DoWave ();
}
}
void DoWave()
{
Debug.Log ("wave is happening");
waveInProgress = true;
if (waveNumber == 1)
{
//do wave 1
Wait (5);
}
if (waveNumber == 2)
... (irrelevant code)
waveInProgress = false;
}
IEnumerator Wait(float duration)
{
yield return new WaitForSeconds(duration);
}
}
(the other script that changes the waveNumber):
if (!GameObject.Find ("WaveController").GetComponent<Waves> ().waveInProgress) //if a wave is not already in progress...
{
if (GUI.Button (new Rect (Screen.width - 140, 10, 120, 20), "start wave " + (GameObject.Find ("WaveController").GetComponent<Waves> ().waveNumber+1)))
{
GameObject.Find ("WaveController").GetComponent<Waves> ().waveNumber += 1;
}
}