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 nvent3 · Aug 23, 2014 at 06:16 AM · pause

Pausing game

Hi, I have problem with my game for mobile devices. My player is jumping using touch screen (Input.GetMouseButtonDown(0)). Now, I wanted to do pausing button, but when I'm touching this button my player is jumping. How can I do this pause without jumping? This is pausing script: > using UnityEngine; using > System.Collections; > > public class PauseScript : > MonoBehaviour { public bool CanPause; > void Start() { CanPause = true; } > void OnGUI() { if (GUI.Button (new > Rect (Screen.width - (Screen.width / > 60) - Screen.width / 20, Screen.height > / 60, Screen.width / 20, Screen.width > / 20), "Pause")) { if (CanPause) > { > Time.timeScale = 0; > CanPause = false; } else { > Time.timeScale=1; > CanPause = true; } } } }

Of course, I need it in C#.

Thanks in advance.

Comment
Add comment · Show 1
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 Ekta-Mehta-D · Aug 23, 2014 at 06:21 AM 0
Share

Please format your code. so it will be easy to understand.

1 Reply

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

Answer by supernat · Aug 23, 2014 at 06:49 AM

If you're lucky, OnGUI might be called first, before OnMouseDown. If so, you can simply create a global variable "clickedButton" and set it to true when the GUI.Button returns true. Then test it in your OnMouseDown for being false before jumping. And then reset it to false there. Now that's a pretty nasty hack, and it probably doesn't lend itself well to future expansion in your UI. But for a simple case where you only have a button or two but otherwise allow jumping with a click anywhere else, it would in theory work just fine (if OnGUI is called first before OnMouseDown).

Assuming you aren't lucky, then an alternative is to create a quad, untextured, assign a collider to it, and move the OnMouseDown() method to a script on that quad. Now make that quad full screen and always in front of the camera. Since the quad is in the geometry, the UI will always receive input from the mouse at a higher priority. The downside is that you have a quad that gets in the way when you want to select stuff, so try to make it very small and very close to the camera (make the camera its parent).

Comment
Add comment · Show 1 · 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
avatar image nvent3 · Aug 23, 2014 at 03:24 PM 0
Share

Unfortunately, I'm not lucky.. (Or I'm doing it wrong.) I will try this alternative method.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Listen to audio when stepping frame by frame in editor 1 Answer

How to pause game when receiving phone call on Android 6? 2 Answers

How to stop Audio Track in Timeline? 1 Answer

How to enable UI collision while timeScale is 0? 2 Answers

Pause menu... Isn't pausing everything... 1 Answer


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