这是我一段时间以来遇到的最烦人的错误。 我想使用 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.Collections
和IEnumerator<T>
位于System.Collections.Generic
。因此,请确保您拥有正确的匹配对。
关于c# - 当前上下文中不存在名称 IEnumerator,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31416514/