- Home /
Question by
jayman2505 · Apr 04, 2015 at 07:55 PM ·
coroutineoptimization
Using Coroutines and OnGui Together
I'm looking for a better way to partner Coroutines and OnGUI. The following example works but not well (button clicks get missed and stop working after a while), so I'm wondering if there is any different way to design this:
using UnityEngine;
using System.Collections;
public class LatentController : MonoBehaviour {
public int Count = 0;
bool UserInput=false;
IEnumerator TestInput()
{
while (true)
{
if (!UserInput)
{
Debug.Log("Round: "+Count);
//do any calculations until we need more user input
UserInput = true;
}
if (UserInput)
{
yield return new WaitForEndOfFrame();
}
}
}
void OnGUI()
{
if (UserInput)
{
if (GUI.Button(new Rect(10, 10, 150, 100), "Reset"))
{
UserInput = false;
Count=0;
}
if (GUI.Button(new Rect(10, 120, 150, 100), "Continue"))
{
UserInput = false;
Count++;
}
}
}
// Use this for initialization
void Start ()
{
StartCoroutine(TestInput());
}
}
Comment
Your answer

Follow this Question
Related Questions
Calculating the Exact Center of Multiple Objects 2 Answers
Performance issues with GetComponent/gameObject.Find in different functions 1 Answer
Will calling a Coroutine every time the player shoots an object a bad way to program? 1 Answer
Optimization: Central "update" system vs using Updates 1 Answer