Unity3D Coroutine编译器错误
本文关键字:错误 编译器 Coroutine Unity3D | 更新日期: 2023-09-27 18:00:04
我是unity的初学者,我正在尝试用协同程序播放动画,但出现了以下错误:
1.error CS1502:与UnityEngine.MonoBehaviour.StartCoroutine(System.Collections.IEnumerator)' has some invalid arguments
2.error CS1503: Argument
#1"匹配的最佳重载方法无法转换System.Collections.IEnumerable' expression to type
System.Collections.IEnumerator"
代码:
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);
}
}
对于IE分子。。。
IEnumerator Go(){
while (true) {
animation.Play();
yield return new WaitForSeconds(3f);
}
}
一个Coroutine的返回类型将是IEnumerator。