I’m trying to fire an IEnumerator (C#) routine from Update. I can see that the line gets there in Update, I set a break point there ok. But breakpoints in the coroutine are never hit, and nothing seems to happen. It’s like the routine is not called, and I don’t know why.
public class FrameUploader : MonoBehaviour
{
public Texture2D texture;
public float frameRate = 1f;
public string prepend = "user0_";
public int frameNum = 0;
public bool showing = true;
public string server = "http://myserver/uploadimage.php";
float lastFrameTime = 0f;
int q = 0;
// May want to do this on physics update or late update?
void Update ()
{
if ((Time.time - lastFrameTime) >= 1f/frameRate)
{
lastFrameTime = Time.time;
QueueTexture(); // It gets here, if I set a breakpoint here
}
}
IEnumerator QueueTexture()
{
// Cannot stop at any breakpoints here. 'q' never changes according to OnGUI
WWW wwwToUpload = null;
byte[] bytes = texture.EncodeToPNG();
WWWForm form = new WWWForm();
form.AddField("frameNum", frameNum);
form.AddBinaryData("fileUpload", bytes, prepend+frameNum+".png", "image/png");
wwwToUpload = new WWW (server+frameNum, form);
q++;
frameNum++;
yield return wwwToUpload;
wwwToUpload = null;
form = null;
q--;
}
void OnGUI()
{
if (showing)
{
GUI.Label (new Rect (10, Screen.height-30, 200, 20), "Q: "+q);
}
}
}