The name IEnumerator does not exist in current context

Var14ble picture Var14ble · Jul 14, 2015 · Viewed 13.1k times · Source

This is the most annoying error I've had in a while. I want to make a simple loop to move my camera to another point in Unity, using C#.

I'm "using System.Collections.Generic", and IEnumerator even shows up in the suggestions when I start typing it, but as soon as I'm done, it goes red and has an error that reads "Assets/Scripts/NerworkManager.cs(190,9): error CS0246: The type or namespace name `IEnumerator' could not be found. Are you missing a using directive or an assembly reference?" in the console, and "error CS0103: The name IEnumerator does not exist in the current context" in the editor.

Here's my code:

IEnumerator LerpCam(Camera c, Vector3 target, float length){
        float startTime = Time.time;
        while (Time.time < startTime + length) {
            c.transform.position = Vector3.Lerp (c.transform.position, target, Time.deltaTime);
        }
    yield return null;
}

I have no idea what the problem is, and am able to use other things from the Generic collection without problems. Any help would be greatly appreciated.

Answer

jsanalytics picture jsanalytics · Jul 14, 2015

IEnumerator is in System.Collections and IEnumerator<T> is in System.Collections.Generic. So make sure you have the correct matching pair.