0

I am working on a project in Unity3d and I was writing some code and initially I had the IEnumerator as Start instead of RunThis and the code ran fine, now I went to move it in to a new method and it didn't do anything. Could Someone explain this?

using UnityEngine;
using System.Collections;

public class UniDLC : MonoBehaviour
{
    void Start() {
        RunThis();
    }
    IEnumerator RunThis()
    {
        Debug.Log("ran");
        string url = "file://C:\\Users\\tom\\Documents\\test.txt";
        WWW www = new WWW(url);
        yield return www;
        Debug.Log(www.text);
    }
}

P.s. I anticipate at least someone telling me about unityanswers, yes I know it exists but the site bugs out too much and I am sure someone hear can answer this, thank you.

4

1 に答える 1

4

RunThis() によって返されるIEnumeratorを実際に使用しようとしない場合、コンパイラは列挙子を呼び出さないため、コードは呼び出されません。

列挙されたオブジェクトを 1 つだけ返すため、

RunThis().MoveNext();

列挙子が機能していることを示す必要があります。

于 2012-07-23T04:38:59.490 に答える