简体   繁体   中英

Unity3D Coroutine compiler error

I'm a complete beginner in unity, and i'm tring to play an animation with a coroutine, but get the following erros:

1.error CS1502: The best overloaded method match for UnityEngine.MonoBehaviour.StartCoroutine(System.Collections.IEnumerator)' has some invalid arguments 2.error CS1503: Argument #1' cannot convert System.Collections.IEnumerable' expression to type System.Collections.IEnumerator'


The code:

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

}

change

IEnumerable Go(){
    while (true) {
        animation.Play();
        yield return new WaitForSeconds(3f);
    }
}

for a IEnumerator...

IEnumerator Go(){
    while (true) {
        animation.Play();
        yield return new WaitForSeconds(3f);
    }
}

协程的返回类型将是IEnumerator。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM