I am learning Unity with C# and studying the GUI Button. I found the following statement in Unity documentation:
"This means that your OnGUI implementation might be called several times per frame (one call per event). "
using UnityEngine;
using System.Collections;
public class ExampleClass : MonoBehaviour {
void OnGUI() {
if (GUI.Button(new Rect(10, 10, 150, 100), "I am a button"))
print("You clicked the button!");
}
}
My questions are:
1) The above "if" statement will keep detecting the condition until it is true. It should be called polling input. Why does the above code use polling input instead of event driven input? (i.e. When someone press the button, the event is fired.). Although the if-statement will do nothing if the condition is false, it is keep detecting and not efficient compared with event driven input.
2) Why Unity use polling input in this case?
3) The above statement mention that "one call per event". Does it mean it is actually a event driven input, not polling input?
I am confusing about these questions and can't find the answer. Would someone explain to me. Thanks.