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();
}
}