Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 UniqueProductionZ · Jan 08, 2014 at 06:46 PM · pause menuresumepausegameunpause

Creating a Unpause Button/Resume Game Button

I have started creating a Pause menu however i am stuck creating the unpause menu button for my pause menu. I have tried everything. I have looked all over google and Unity and i couldnt find a working solution/script.

Here is my Pause menu script, It is not finished yet but this is where i have got to until i need to create my resume game button:

 var mainMenuSceneName : String;
 private var pauseEnabled = false;
 
 
 function Start(){
     pauseEnabled = false;
     Time.timeScale = 1;
     AudioListener.volume = 1;
     Screen.showCursor = false;
 }
 
 function Update(){
 
     //check if pause button (escape key) is pressed
     if(Input.GetKeyDown("escape")){
     
         //check if game is already paused        
         if(pauseEnabled == true){
             //unpause the game
             pauseEnabled = false;
             Time.timeScale = 1;
             AudioListener.volume = 1;
             Screen.showCursor = false;            
         }
         
         //else if game isn't paused, then pause it
         else if(pauseEnabled == false){
             pauseEnabled = true;
             AudioListener.volume = 0;
             Time.timeScale = 0;
             Screen.showCursor = true;
         }
     }
 }
 function OnGUI(){
 
     if(pauseEnabled == true){
     
                 if(GUI.Button(Rect(Screen.width /2 - 100,Screen.height /2 ,250,50), "Options")){
         if(pauseEnabled == true){
             //unpause the game
             pauseEnabled = false;
             Time.timeScale = 1;
             Screen.showCursor = false;
             }
         }
 }

Please can you tell me how to fix my script because i am getting a error saying that it is expecting "{" instead it found ". I have no idea how to fix it.

Can you please post a basic resume game button for my script that will work (My script it written in Javascript)

Or

Can you give me the code for a resume game and i can implement the code into my script.

Thanks in advanced.

UniqueGaming

Comment
Add comment · Show 2
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 UniqueProductionZ · Jan 08, 2014 at 07:52 PM 0
Share

Bump! I really need to do this.

avatar image Gruffy · Jan 08, 2014 at 08:35 PM 0
Share

Just answered it below for you matey , check out Answer | | V

1 Reply

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

Answer by Gruffy · Jan 08, 2014 at 08:10 PM

Here you go matey. Just copy this revised code over and you ll be fine (this obviously needs to be attached to a gameobejct in your scene. #pragma strict var mainMenuSceneName : String; private var pauseEnabled = false;

     function Start()
     {
     pauseEnabled = false;
     Time.timeScale = 1;
     AudioListener.volume = 1;
     Screen.showCursor = false;
     }
      
     function Update()
     {
         //check if pause button (escape key) is pressed
         if(Input.GetKeyDown("escape"))
         {
             //check if game is already paused
             if(pauseEnabled == true)
             {
                 //unpause the game
                 pauseEnabled = false;
                 Time.timeScale = 1;
                 AudioListener.volume = 1;
                 Screen.showCursor = false;
             }
          
             //else if game isn't paused, then pause it
              else if(pauseEnabled == false)
             {
                 pauseEnabled = true;
                 AudioListener.volume = 0;
                 Time.timeScale = 0;
                 Screen.showCursor = true;
             }
         }
     }//end Update function
     function OnGUI()
     {
      
         if(pauseEnabled == true)
         {
             if(GUI.Button(Rect(Screen.width /2 - 100,Screen.height /2+25 ,250,50), "Option"))
             {
                 Debug.Log("GUI.Button : Options : pressed");
             }
             if(GUI.Button(Rect(Screen.width /2 - 100,Screen.height /2-25 ,250,50), "Resume"))
             {
                 if(pauseEnabled == true)
                 {
                     //unpause the game
                     pauseEnabled = false;
                     Time.timeScale = 1;
                     Screen.showCursor = false;
                     AudioListener.volume = 1;
                 }
             }
         }
 }//end OnGUI function    




Your issue was curly braces.

as a humble tip: When you look at a debugger line in the Unity Console....

Assets/dunno.js(61,1): BCE0044: expecting }, found ''.

Consider it in three parts.

Like so... It is saying in the first section

Assets/YourScript.js(61,1)

that the error comes from the script named (YourScript)... In the second section

BCE0044: expecting },

it`s telling you what the compiler was expecting to find, in this case a "}" closing curly brace, to end your function body.

Thirdly, it is simply telling you WHAT it ACTUALLY found/discovered, in this case nothing!, Nada!, nowt. Represented by the '' part at the end of the sentence.

SO if you can split it into those three each time, you wont go far wrong and any variations, now you know this, are only ever slight with respect to the error statements Unity throws.

Anyhoo, hope that helped ya bud.. If so mark it as an answer as it may help others in the same pickle. Also, try here for a few pointers and tips for good Unity development...

Unity Tuts

Unity Gems

take care bud and thanks for reading Gruffy

Comment
Add comment · Show 2 · 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 UniqueProductionZ · Jan 08, 2014 at 09:26 PM 0
Share

O$$anonymous$$G Thank you so much! This worked all i had to do was add private var pauseEnabled = false; at the top of the code and it worked without any errors. Thanks

UniqueGa$$anonymous$$g

avatar image Gruffy · Jan 08, 2014 at 09:36 PM 0
Share

ooops, sorry just noticed that i didn`t add back your vars at the top. Im just stupid sometimes! Anyway, No problems, anytime.

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

19 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

Related Questions

Why doesnt my resume button work 0 Answers

Resume Button / Pause Menu odd interaction 2 Answers

Countdown after resume game. 4 Answers

Delaying Time.timeScale =1 when unpausing (to allow time for animation to clear) 1 Answer

Lock camera when paused 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