- Home /
touch buttons function OnGUI issue
I am trying to make a touch button function for android.
You would call touch.Button and have options similar to the GUI.Button, but there is an issue
I want to be able to use labels and images for this button, because of this I am calling the function in OnGUI.
This on the other hand gets triggered much faster than the Update function, so it tends to return true multiple times for a button triggered when touched down using touch.phase = TouchPhase.Began
I could call it out of the Update function, but then I would no longer be able to use Labels (I could still use Graphics.DrawTexture for images)
I tried many things but couldn't find a good solution.
Thanks in advance
Answer by Xumbu · May 20, 2014 at 06:03 PM
mouse or touch events will be checked every frame.
OnGUI is called multiple times every frame.
So use somethink like this:
long lastCheckFrameCount = 0;
private bool onGuiCheckTouch()
{
if(Time.frameCount == lastCheckFrameCount)
{
return false;
}
else
{
lastCheckFrameCount = Time.frameCount;
return Input.touchCount > 0;
}
}