I need a functor inside my OnGUI() function which draws a GUI.Button after an input.
So I try to do this
void OnGUI()
{
System.Action Some = () =>
{
if (Input.GetKeyDown(KeyCode.Q))
GUI.Button(new Rect(0, 0, 100, 20), "Done");
};
Some();
}
Nothing happens but when I use that
void OnGUI()
{
System.Action Some = () =>
{
GUI.Button(new Rect(0, 0, 100, 20), "Done");
};
Some();
}
GUI.Button appears, so the functor works well. But it doesn’t fit my needs. So I figured out that problem doing brute-force
bool isSome = false;
void OnGUI()
{
System.Action Some = () =>
{
if (Input.GetKeyDown(KeyCode.Q))
isSome = true;
if(isSome)
GUI.Button(new Rect(0, 0, 100, 20), "Done");
};
Some();
}
It seems to me not good at all.
Can someone explain me why doesn’t GUI element appear after an action (without bool flag)?
Thanks in advance!