C# Unity3D协同程序编译器错误
我是unity的一名完全初学者,我正尝试使用协同程序播放动画,但遇到以下错误: 错误CS1502:C# Unity3D协同程序编译器错误,c#,unity3d,coroutine,C#,Unity3d,Coroutine,我是unity的一名完全初学者,我正尝试使用协同程序播放动画,但遇到以下错误: 错误CS1502:UnityEngine.MonoBehavior.Start例程(System.Collections.IEnumerator)”的最佳重载方法匹配具有一些无效参数 2.错误CS1503:参数#1'无法将System.Collections.IEnumerable'表达式转换为类型System.Collections.IEnumerable' 守则: using UnityEngine;
UnityEngine.MonoBehavior.Start例程(System.Collections.IEnumerator)”的最佳重载方法匹配具有一些无效参数
2.错误CS1503:参数
#1'无法将System.Collections.IEnumerable'表达式转换为类型
System.Collections.IEnumerable'
守则:
using UnityEngine;
using System.Collections;
public class Trap : MonoBehaviour {
//public float delayTime;
// Use this for initialization
void Start () {
StartCoroutine (Go ());
}
// Update is called once per frame
void Update () {
}
IEnumerable Go(){
while (true) {
animation.Play();
yield return new WaitForSeconds(3f);
}
}
}
改变
IEnumerable Go(){
while (true) {
animation.Play();
yield return new WaitForSeconds(3f);
}
}
对于一个IEnumerator
IEnumerator Go(){
while (true) {
animation.Play();
yield return new WaitForSeconds(3f);
}
}
协同程序的返回类型将是IEnumerator。如果您想知道原因,错误很明显。。。调用start例程()时,需要添加类型为System.Collections.IEnumerator的参数。。。由于您将“GO”声明为IEnumerable,这就是您出现此错误的原因……名称非常相似,很难记住错误所在。使用给定的答案还可以查看您发布的错误消息。这让你看到了问题所在。重点学习从错误消息中提取含义。根据您使用的tbe编辑器,它甚至可能会建议修复。