Question

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.

Was it helpful?

Solution

If you don't try to actually use the IEnumerator returned by RunThis(), the compiler will not invoke the enumerator, so your code will not be called.

Since you are only returning one enumerated object,

RunThis().MoveNext();

should show the enumerator working.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top