Does a method has to return IEnumerator if you want to yield inside it?

Hi,

Does a method has to return IEnumerator if you want to yield inside it? I mean if you don’t StartCoroutine it, then it still has to return IEnumerator, right?

I think it does but I don’t know why. I don’t want this code to co-run with my main code, I just want it to WaitForSeconds somewhere and then resume:

	public IEnumerator ExplodeMeNAOW()
	{
		Debug.Log("Self destruct initiated, sir! :(");

		GetComponentInChildren<ParticleEmitter>().Emit();
		
		Destroy(gameObject);
		yield return new WaitForSeconds(2f);
//		Application.LoadLevel("GameOver");
	}

In order to use a yield statement, you need to return an IEnumerator (making your function a coroutine). If you don’t want to make your function a coroutine, then you’ll need to put your code to wait for 2 seconds in your Update() loop and just eat up calls until Time.deltaTime adds up to 2.0f. The whole point of using yield is that it returns the flow of the program back so that other things can process (it ‘yields’ the clock cycles).