IEnumerator does not exist

using UnityEngine;
using System.Collections;

public class DoorLogic : MonoBehaviour {

	public float guiBoxWidth;
	public float guiBoxHeight;

	public Transform theDoor;

	private bool drawGUI = false;
	public bool isClosed = true;

	// Update is called once per frame
	void Update () 
	{
		if (drawGUI == true && Input.GetKeyDown (KeyCode.E)) 
		{
			ChangeDoorState();
		}
	}


	void OnTriggerEnter(Collider collider)
	{
		if (collider.tag == "Player") 
		{
			Debug.Log("Working");
			drawGUI = true;
		}
	}

	void OnTriggerExit(Collider collider)
	{
		if (collider.tag == "Player") 
		{
			Debug.Log("Exit Working");
			drawGUI = false;
		}
	}

	void OnGUI()
	{
		if (drawGUI == true) 
		{
			if (isClosed == true)
				GUI.Box (new Rect ((Screen.width / 2) - 51, 10, guiBoxWidth, guiBoxHeight), "Press E to Open");

			else
				GUI.Box (new Rect ((Screen.width / 2) - 51, 10, guiBoxWidth, guiBoxHeight), "Press E to Close");
		}
	}

	void ChangeDoorState()
	{
		if (isClosed == true) 
		{
			theDoor.animation.CrossFade ("Opening");
			isClosed = false;
		}

		StartCoroutine (doorDelay(2));

		theDoor.animation.CrossFade ("Close");
		isClosed = true;
	}

   //IEnumerator is in redfont.
	IEnumerator doorDelay(float delaySec)
	{
		yield return new WaitForSeconds(delaySec);
	}
}

I get this error “The name ‘IEnumerator’ does not exist in the current context”. and the IEnumerator is in redfont.

alt text

if it’s not the case, try to add “using System.Collections”

I know you put it in your copy and paste , but In my case it was that…

I know this is old, but just found this from Google so I thought I’d comment.

I just had the same issue and it was fixed by restarting Unity.

I tryed your script and i get no error.Try making a new script and copy everything from it again.

@fullme7al : I think it’s a bug too.

I’m trying to follow the Space Shooter tutorial and get the same error “CS0103” …
I am under Windows 8.1 too.
Could this be related to a version of the .Net framework installed (or missing) on the system ?
Maybe trying to install a 3.5 version of the .Net framework for Windows 8.1 could do it, is it possible ?

Updated, some hours later :
In fact, it was : under Windows 8.1, only the 4.5 or 4.0 versions ('don’t remember) of the .net framework are installed and activated. The 3.5 is available, but not activated by default. After following the procedure given here : Installez .NET Framework 3.5 sur Windows 11, 10, 8.1, 8 - .NET Framework | Microsoft Learn, i have activated the 3.5 version (and after some additional file download), re-opened Unity 3D, checked my script (the GameController in the Space shooter tutorial) and IEnumerator is now properly identified and the script works !

Try using System.Collection.Generic namespace

did anybody solve this problem ?

it’s 2017 now and i’m using Unity 5.6 on Linux Mint

i have the exact same problem !

befor use IEnumerator , Use void :
void IEnumarator DoorDalay(float delaySec)
{
yield return new WaitForSeconds(delaySec);
}