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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by $$anonymous$$ · Aug 24, 2014 at 12:46 PM · booleanpause gamelock-cursor

Confusion on simple pause screen

Ok. I am making a simple pause screen. When the player presses Escape, I want it to show the word "Paused" (in the form of a GUIText) and show the cursor(I have Screen.lockCursor enabled in the begining). Here is the basic script I have so far: #pragma strict

 public var PauseText : GUIText;
 
 private var EscActive;
 
 function Start () 
 {
     EscActive = false;
     Screen.lockCursor = true;
     PauseText.active = false;
 }
 
 function Update () 
 {
     if(Input.GetKey(KeyCode.Escape) && EscActive == false)
     {
         EscActive = true;
         Screen.lockCursor = false;
         PauseText.active = true;
     }
     
     if(Input.GetKeyDown(KeyCode.Escape) && EscActive == true)
     {
         EscActive = false;
         Screen.lockCursor = true;
         PauseText.active = false;
     }
 }
Comment
Add comment · Show 3
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 renezuidhof · Aug 24, 2014 at 01:12 PM 1
Share

So, what is your problem? What is your question

Pausing a game can be done with: Time.timeScale = 0 (unpause = 1).

P.S. Little programmers tip: in your if-statement, when using a boolean you don't have to compare it to another boolean. EscActive == true is the same as EscActive. Or EscActive == false is the same as !EscEscape.

avatar image $$anonymous$$ · Aug 24, 2014 at 02:13 PM 0
Share

Awesome. Thanks for the tips! I had a small blank on how to freeze the time. :D

avatar image $$anonymous$$ · Aug 24, 2014 at 02:24 PM 0
Share

Sadly, though, I am still having a similar problem. It won't bring up the text or pause the game. Here is the updated code (I am at a brick wall :\ ):

#pragma strict public var PauseText : GUIText; private var EscActive; function Start () { EscActive = false; Screen.lockCursor = true; PauseText.active = false; } function Update () { if(Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.Escape) && !EscActive) { EscActive = true; Screen.lockCursor = false; PauseText.active = true; Time.timeScale = 0; } if(Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.Escape) && EscActive) { EscActive = false; Screen.lockCursor = true; PauseText.active = false; Time.timeScale = 1; } }

To be completely honest, it may be in the way I wrote the code that it messes up. I am not sure if I am confusing the computer or if I am putting in some wrong code the wrong way.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Tonyx97 · Aug 24, 2014 at 02:29 PM

You can try show the text with a simple OnGUI function like this:

 function OnGUI ()
 {
     if (!EscActive) return;
     GUI.Label ( Rect (Screen.width/2, Screen.height/2, 100, 100), "Pause" );
 }
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 $$anonymous$$ · Aug 24, 2014 at 11:23 PM 0
Share

I'll give it a try thanks. :)

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

24 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 avatar image avatar image

Related Questions

Is a global static boolean a good implementation for pausing my game? 2 Answers

Making a pause menu resume 2 Answers

Is it a BUG? Cursor Lock FS Mode in Mac Safari 1 Answer

Mouse cursor doesn't lock Unity 5 0 Answers

boolean flicker 3 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