In my application, I create buttons like this:
if(GUILayout.Button(GUIContent(menuButton.text), menuButton.getGuiStyle())){
menuButton.executeClick();
}
So whenever the button is clicked the executeClick() function is called on it. Now I also have a window behind the buttons that accepts user input and queries on every Update() with
if(Input.touchCount > 0){
var touch : Touch = Input.GetTouch(0);
//use the touch...
When I click a button, the code used to interpret the touch event is executing when I really only want the menu button code to in executeClick(). What’s a good way that I can first check if a button is clicked and if none are to use the touch information?
Am I making a bad assumption that the first is always called before the second?
Yes, it is a bad assumption. Execution order is documented here:
Also consider here it is stated that:
OnGUI: Called multiple times per frame in response to GUI events. The Layout and Repaint events are processed first, followed by a Layout and keyboard/mouse event for each input event.
Why don’t you just put your second logic inside first logic:
if(GUILayout.Button(GUIContent(menuButton.text), menuButton.getGuiStyle())){
menuButton.executeClick();
if(Input.touchCount > 0){
var touch : Touch = Input.GetTouch(0);
//use the touch...
}
Or inside executeClick that you can be sure that touch check is made inside(after) the click.
Or else you have to be more clear about what you are trying to achieve that I could provide a more precise help.