- Home /
GUI.Button Touch Input Problem
I'm attempting to create a pause menu on Android. I'm using GUI buttons and from what I've read it should work with touch input, just like a mouse.
The code below works with a mouse and touch input will work if the mouse is over the GUI button. Obviously something weird is going on with the position of the touch.
Any help would be really appreciated. using UnityEngine; using System.Collections;
public class pauseScript : MonoBehaviour {
public bool isPaused = false;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if(Input.touchCount >= 2){
isPaused = true;
}
}
void OnGUI(){
if(isPaused){
Time.timeScale = 0.0001f;
thePauseMenu ();
}
}
void thePauseMenu(){
//layout start
GUI.BeginGroup(new Rect(Screen.width / 2 - 150, 50, 300, 250));
//the menu background box
GUI.Box(new Rect(0, 0, 300, 250), "");
//logo picture
GUI.Label(new Rect(15, 10, 300, 68), "logoTexture");
///////pause menu buttons
//game resume button
if(GUI.Button(new Rect(55, 100, 180, 40), "Resume")) {
//resume the game
Time.timeScale = 1.0f;
isPaused = false;
//disable pause menu
print ("Resume button");
}
//main menu return button (level 0)
if(GUI.Button(new Rect(55, 150, 180, 40), "Main Menu")) {
Application.LoadLevel(0);
}
//quit button
if(GUI.Button(new Rect(55, 200, 180, 40), "Quit")) {
Application.Quit();
}
//layout end
GUI.EndGroup();
}
}
could you send a screenshot from pc and one from your touch device
@Swaggre - as long as the function is called from within OnGUI(), then it is fine.
@aclee - Here is a screen from the unity editor: http://imgur.com/2gk8ZIU you can see how 'resume' is highlighted from the mouse hovering over it. Touching the 'Resume' button while the mouse is over it will work. Otherwise nothing happens.
Answer by jstation · May 03, 2014 at 05:58 PM
I just did a build and ran it straight off my phone (not using unity remote) and the bui.button are working. I feel dumb, but hopefully this will help someone out.
Your answer
Follow this Question
Related Questions
multi touch / swipe issues 5 Answers
How to detect a touch android c# 0 Answers
How to prevent touch going through UI? 3 Answers
Problem with multi-touch on android game 1 Answer
Android touch gui help!!! 2 Answers