I want to display the wave number before every incoming wave of enemies. And after displaying this it should hide the text component. I tried to get this done with StartCoroutine() and Ienumerator but that does not seem to work as it runs only once. As in Wave 1 is displayed and nothing after wards.
Below is the script I am using for this:
public class WaveUpdateTextScript : MonoBehaviour
{
[SerializeField]
WaveSpawner spawner;
private WaveSpawner.SpawnState currentState;
private Text waveDisplay;
// Use this for initialization
void Start()
{
waveDisplay = GetComponent<Text>();
StartCoroutine(WaveDisplaySwitch());
}
IEnumerator WaveDisplaySwitch()
{
switch (spawner.NextWave)
{
case 1:
waveDisplay.text = "Wave 1 of 8 !!";
yield return new WaitForSeconds(4f);
gameObject.SetActive(false);
break;
case 2:
gameObject.SetActive(true);
waveDisplay.text = "Wave 2 of 8 !!";
yield return new WaitForSeconds(4f);
gameObject.SetActive(false);
break;
case 3:
gameObject.SetActive(true);
waveDisplay.text = "Wave 3 of 8 !!";
yield return new WaitForSeconds(4f);
gameObject.SetActive(false);
break;
default:
Debug.Log("This be the meh wave...");
break;
}
}
}
I know whats going on, on start()
the coroutine is started once and then case 1 of switch
works and then stops at break
.
How would I solve this? or is this not the best way of achieving the desired result?