- Home /
How to make a GUI.button react to touch ?
How do I make it so, that a GUI button makes me load the main menu when it is touched ? I have the button working for me. The following is the code for it:
 void OnGUI()
     {
 if (GUI.Button(new Rect(Screen.width / 3, Screen.height /2, 150, 25),"Play Again"))
         {
             Application.LoadLevel("MainMenu");
         }
 
 if (GUI.Button(new Rect(Screen.width / 3, Screen.height /2 + 50, 150, 25),"Quit Game"))
         {
             Application.Quit();
         }
    }
Answer by NickP_2 · Jun 01, 2014 at 01:37 PM
If you are using a device with Unity remote connected to the editor, the GUI buttons are kinda...strange:
The position of the touch is wherever the mouse cursor is, and the left click is performed by doing a touch on the screen. Also the mouseclick should do a click.
When you build the game to a device, GUI buttons should work perfectly with touch!
Oh ! So does that mean that my buttons are already working, but since I'm using the Remote connected to the editor, it won't work ? Because, I really am using the Remote to test out the playability of the menu screen.
Yes indeed, try building it to your device, and it should work !
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                