Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by jstation · May 02, 2014 at 11:22 PM · c#androidguitouch

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(); 
     }
 }
 
Comment
Add comment · Show 4
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image aclee · May 03, 2014 at 08:39 AM 0
Share

could you send a screenshot from pc and one from your touch device

avatar image Swaggre · May 03, 2014 at 10:00 AM 0
Share

I think you have to put all GUI stuff inside OnGUI()

avatar image robertbu · May 03, 2014 at 02:26 PM 0
Share

@Swaggre - as long as the function is called from within OnGUI(), then it is fine.

avatar image jstation · May 03, 2014 at 05:28 PM 0
Share

@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.

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

22 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges