c# - 当前上下文中不存在名称 IEnumerator

标签 c# unity-game-engine ienumerator

这是我一段时间以来遇到的最烦人的错误。 我想使用 C# 创建一个简单的循环,将相机移动到 Unity 中的另一个点。

我正在“使用 System.Collections.Generic”,当我开始输入时,IEnumerator 甚至会出现在建议中,但是一旦我完成,它就会变成红色,并显示一个错误,内容为“Assets/Scripts/NerworkManager.cs(190,9):错误 CS0246:找不到类型或命名空间名称“IEnumerator”。是否缺少 using 指令或程序集引用?在控制台中,并在编辑器中显示“错误 CS0103:名称 IEnumerator 在当前上下文中不存在”。

这是我的代码:

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;
}

我不知道问题是什么,并且能够毫无问题地使用通用集合中的其他内容。任何帮助将不胜感激。

最佳答案

IEnumerator位于System.CollectionsIEnumerator<T>位于System.Collections.Generic 。因此,请确保您拥有正确的匹配对。

关于c# - 当前上下文中不存在名称 IEnumerator,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31416514/

相关文章:

javascript - 在 C# 中解析 JSON 文件 (Unity)

c# - 实现通用 IEnumerator 和 IComparable 的问题

c# - List<T>.Enumerator IEnumerator.Reset()方法实现

c# - 在 XML 文件中包含二进制数据

c# - 如何将字符串转换为 "iso-8859-1"?

unity-game-engine - 我什么时候应该在 Unity 标准着色器上使用 uv1 而不是 uv0

c++-cli - C++/CLI IEnumerable 和 IEnumerator 实现

c# - OData 无法识别我的集合属性

c# - 元组与字符串作为 C# 中的字典键

unity-game-engine - 为什么四元数有四个变量?