- Home /
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.
What is before that? You are probably missing a } just before.
nothing is missing, it's just i cant use it and i don't know why
I put this script in my Unity project and get no warnings. That code doesn't seem to be the problem.
the IEnumerator is in red fonts on the $$anonymous$$onoDevelop
You might be facing the case where you need to copy paste your script, delete it, create a new one and paste the code. $$anonymous$$agically some non existing errors disappear this way.
Answer by ababab5 · May 06, 2015 at 02:19 PM
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..
Answer by Marc Ollivrin · Apr 02, 2014 at 09:39 AM
@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 : http://msdn.microsoft.com/fr-fr/library/hh506443%28v=vs.110%29.aspx, 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 !
Answer by dennyroberts · Jun 30, 2017 at 03:56 PM
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.
Answer by morteza_asadpour · Dec 02, 2013 at 06:59 AM
befor use IEnumerator , Use void : void IEnumarator DoorDalay(float delaySec) { yield return new WaitForSeconds(delaySec); }
Does anyone else have this problem? or solve it? I'm getting the same error as OP in all of my scripts with IEnumerators on my project. Putting void before Ienumerator turns the name of the enumerator blue and throws up several other errors. Is this a bug? I'm up to date on $$anonymous$$onodevelop and Unity. I'm also running Windows 8.1, I wonder if it has something to do with that.
@morteza_asadpour dude...
void IEnumerator
? void in "void my$$anonymous$$ethod(){}" signifies thatmy$$anonymous$$ethod
doesn't return anything. IEnumerator in"IEnumerator my$$anonymous$$ethod() {yield return something;}
" means thatmy$$anonymous$$ethod
will return an "`IEnumerator`" - you can't put two return types in your method signature. Please learn your basics before you start posting answers.
I get the same errors in all of my scripts and also in the Script "GameController" in the "Done/Done_Script" - Folder of the Shooter Tutorial
"Error CS0103: The name 'IEnumerator' does not exist in the current context"
Any Solutions??
What Operating system are you using? I'm using windows 8.1 and ienumerators dont work at all, whether they are my scripts or unity imported projects.I think it is a bug.
Answer by RedDevil · Feb 12, 2014 at 03:22 PM
I tryed your script and i get no error.Try making a new script and copy everything from it again.
Your answer
Follow this Question
Related Questions
Create a class like WWW which a IEnumerator will wait on. 0 Answers
Yield Wait for Seconds (A little help here) 2 Answers
Only the first half of my coroutine works 1 Answer
Wait For Seconds c# 3 Answers
IEnumerator solution! 1 Answer