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 f1shhy · Mar 18, 2013 at 10:35 AM · timerpausegame over

No esc when game over.

So I got a nice press esc to pause the game. And you can get out of time (game over) But when you are game over you can still press esc. I tried something with a noEsc but it didn't work.

Anyone can help me out?

 **My pause script**
 
 var isPaused : boolean = false;
 
 function Update () {
     if(Input.GetKeyDown("escape") && !isPaused){
         Time.timeScale = 0.0;
         isPaused = true;
     }
     else if (Input.GetKeyDown("escape") && isPaused){
         Time.timeScale = 1.0;
         isPaused = false;
     }
 }
 
 function OnGUI () {
     if(isPaused){
         GUI.Box (Rect (490,250,300,160), "game menu");
         if(GUI.Button (Rect (590,310,100,20), "restart")){
             //ResetVariables();
             Application.LoadLevel("level9");
             Time.timeScale = 1.0;
             isPaused = false;
         }
         if(GUI.Button (Rect (590,340,100,20), "continue")){
             Time.timeScale = 1.0;
             isPaused = false;
         }
         if(GUI.Button (Rect (590,370,100,20), "back to menu")){
             Application.LoadLevel("menu");
         }
         GUI.Label (Rect (260,280,242,100), "\t\t\t\t");
     }
 }
 
 @script AddComponentMenu ("GUI/Pause GUI")
 //function ResetVariables()
 //{
 //    gameOver.noEsc = false;
 //}
 
 
 
 **And my game over script**
 
 var timerValue: float = 5; //You can change this in the inspector.
 var myTimer: float;
 
 //var noEsc = false;
 
 //var GuiButtonStyle : GUIStyle;
 //var GuiBoxStyle : GUIStyle;
 
 var timerOutput: GUIText;
 var timeIsUp = false; 
 
 function Start(){
     Time.timeScale = 1.0;
 }
 
 function Awake(){
     myTimer = timerValue;
 }
 
 function Update(){
     if(myTimer > 0){
         myTimer -= Time.deltaTime; 
         var seconds: int = myTimer % 60; 
           var minutes: int = myTimer / 60; 
           timerOutput.text = minutes + ":" + seconds;
     }    
     if(myTimer <= 0){
         timeIsUp = true;
         Time.timeScale = 0.0;
     }
 
 }
 
 function OnGUI(){
     if(timeIsUp == true){    
         GUI.Box (Rect (490,250,300,160), "Game over"/*, GuiBoxStyle*/);
         if(GUI.Button (Rect (590,310,100,20), "restart"/*, GuiButtonStyle*/)){
             //noEsc = true;
             Application.LoadLevel("level9");
             resetTheVariables();
             myTimer = timerValue;
         }
         if(GUI.Button (Rect (590,340,100,20), "menu"/*, GuiButtonStyle*/)){
             resetTheVariables();
             Application.LoadLevel("menu");
         }
     }
 }
 
 @script AddComponentMenu ("GUI/Pause GUI")
 
 function resetTheVariables(){
 //    noEsc = false;
 }
Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by roojerry · Mar 18, 2013 at 02:55 PM

 function Update () {
     if(Input.GetKeyDown("escape") && !noEsc){
        Time.timeScale = 0.0;
        isPaused = !isPaused;
     }
 }

your noEsc code should work as long as you add that case to your Input checking. also, I cut down on your redundant code by just setting isPaused = !isPaused. it's a minor change, but it cuts out an extra case for you

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

11 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

Related Questions

Score wont stop after game is paused 3 Answers

No pausing when game over occurs 1 Answer

pause timer or player using Time.timeScale 1 Answer

Pause at end of game 2 Answers

Pause Menu upon Idle (timer & button issues C#) 0 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