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 andrewjm10 · Jul 04, 2013 at 09:32 PM · errorbuttonsongui

My buttons do not appear when paused?

I am trying to make my own puse script from various tutorials and snippets, it was going ok till i started to add buttons.. At first they would appear even when not paused. not they don't appear at all.

Maybe i am not putting it in the right place? i tried the ONGUI but it kept saying error.

 //My First (Pause Menu) Script 4 July, 2013
 // I'm sure it is full of errors lol, but it's a start!
 // Im using what i am reading in tutorials, plus some code examples..
 
 var paused : boolean = false;
 var pausedGUI : GUITexture;
 var gameName : String = "Game Paused";
 var skin:GUISkin;
 var pauseTexture : Texture2D;
 var windowRect0 : Rect = Rect (670, 250, 150, 50);
 var windowRect1 : Rect = Rect (670, 300, 120, 50);
 var windowRect2 : Rect = Rect (670, 350, 120, 50);
 var windowRect3 : Rect = Rect (670, 400, 120, 50);
 static var backgroundColor : Color;
 
 function Update () {
 
 if(Input.GetKeyDown("p") && paused == false)
 {
 
 //IF GAME IS PAUSED
         paused = true;
         Time.timeScale = 0;
         AudioListener.pause = true;
         Screen.showCursor = true;
         GUI.backgroundColor = Color.blue;
         guiTexture.texture = pauseTexture;
         //GUISkin.CreateInstance new.skin;

 } else if(Input.GetKeyDown("p") && paused == true) {
 
 //IF GAME IS NOT PAUSED
 paused = false;
 AudioListener.pause = false;
 Time.timeScale = 1.0;
 Screen.showCursor = false;
 }
 
 }   
     function OnGUI () {
         //Make New Windows
         if(Input.GetKeyDown("p") && paused == true) {
         guiTexture.texture = pauseTexture;
         guiText.text = gameName;
         GUI.color = Color.green;        
         windowRect0 = GUI.Window (0, windowRect0, PauseWindow, "Resume Game");
         GUI.color = Color.yellow;        
         windowRect1 = GUI.Window (1, windowRect1, PauseWindow, "Load, Save Game");
         GUI.color = Color.yellow;        
         windowRect2 = GUI.Window (2, windowRect2, PauseWindow, "Load, Save Game");
         GUI.color = Color.yellow;        
         windowRect3 = GUI.Window (3, windowRect3, PauseWindow, "Load, Save Game");
         }
     }
     // Make the contents of the window.
     // The value of GUI.color is set to what it was when the window
     // was created in the code above.
     function PauseWindow (windowID : int) {
         if (GUI.Button (Rect (10,20,100,20), "Hello World"))
             print ("Got a click in window with color " + GUI.color);
         // Make the windows be draggable.
         GUI.DragWindow (Rect (0,0,10000,10000));
     }

Im trying to get it to appear as: Game Paused Button 1 Button 2 Button 3 Button 4 with a gray background image

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

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by oliver-jones · Jul 04, 2013 at 09:33 PM

Here try this dude:

 var paused : boolean = false;
 var pausedGUI : GUITexture;
 var gameName : String = "Game Paused";
 var skin:GUISkin;
 var pauseTexture : Texture2D;
 var windowRect0 : Rect = Rect (670, 250, 150, 50);
 var windowRect1 : Rect = Rect (670, 300, 120, 50);
 var windowRect2 : Rect = Rect (670, 350, 120, 50);
 var windowRect3 : Rect = Rect (670, 400, 120, 50);
 static var backgroundColor : Color;
  
 function Update () {
  
     if(Input.GetKeyDown("p") && paused == false){
      
         //IF GAME IS PAUSED
         Time.timeScale = 0;
         AudioListener.pause = true;
         Screen.showCursor = true;
         GUI.backgroundColor = Color.blue;
         guiTexture.texture = pauseTexture;
         //GUISkin.CreateInstance new.skin;
         paused = true;
      
     } 
 
     else if(Input.GetKeyDown("p") && paused == true) {
      
         //IF GAME IS NOT PAUSED
         AudioListener.pause = false;
         Time.timeScale = 1.0;
         Screen.showCursor = false;
         paused = false;
 
     }
 }
  
 
 function OnGUI () {
     //Make New Windows
     if(paused == true) {
         guiTexture.texture = pauseTexture;
         guiText.text = gameName;
         GUI.color = Color.green;        
         windowRect0 = GUI.Window (0, windowRect0, PauseWindow, "Resume Game");
         GUI.color = Color.yellow;        
         windowRect1 = GUI.Window (1, windowRect1, PauseWindow, "Load, Save Game");
         GUI.color = Color.yellow;        
         windowRect2 = GUI.Window (2, windowRect2, PauseWindow, "Load, Save Game");
         GUI.color = Color.yellow;        
         windowRect3 = GUI.Window (3, windowRect3, PauseWindow, "Load, Save Game");
     }
 }
 
 // Make the contents of the window.
 // The value of GUI.color is set to what it was when the window
 // was created in the code above.
 function PauseWindow (windowID : int) {
     if (GUI.Button (Rect (10,20,100,20), "Hello World"))
         print ("Got a click in window with color " + GUI.color);
 
     // Make the windows be draggable.
     GUI.DragWindow (Rect (0,0,10000,10000));
 }

Let me know what happens (I'm not hugely familiar with GUI windows my self, to be honest)

Comment
Add comment · Show 5 · 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 andrewjm10 · Jul 04, 2013 at 09:37 PM 0
Share

Nope, still nothing appears on the screen, but the game does pause. well it still scrolls up down (mouse) for some damn reason make3s it hard to select stuff...

avatar image andrewjm10 · Jul 05, 2013 at 12:18 AM 0
Share

Bump. Any help would be great! If i move the buttons below the if paused they show up. and no error on GUI, so how can i do this.

avatar image ExpiredIndexCard · Jul 05, 2013 at 01:00 AM 0
Share

Can we see your updated script?

avatar image Quillicit · Jul 05, 2013 at 01:45 AM 1
Share

Have you assigned a texture to pauseTexture?

avatar image andrewjm10 · Jul 05, 2013 at 06:09 PM 0
Share

yes i did, sorry i did not reply. i choose a texture to use yes.

avatar image
0

Answer by Crazsta · Jul 05, 2013 at 07:57 AM

Well I know that this isn't exactly what you are trying to make but it should help you see if there is something wrong with your early script as this is the prototype pause I am using in a game I am currently developing. #pragma strict

 var pressed1 : boolean = false;
 var pressed2 : boolean = false;
 public static var paused : boolean = false;
 var sX : int;
 var sY : int;
 
 function Start(){
     sX = Screen.currentResolution.width;
     sY = Screen.currentResolution.height;
 }
 
 function Update () {
 if(Interaction.talking == false){
 if(Input.GetKeyDown(KeyCode.Escape) && pressed1 == false && pressed2 == false){
 pressed1 = true;
 paused = true;
 }
 
 if(pressed2 == true && pressed1 == true){
 pressed1 = false;
 pressed2 = false;
 paused = false;
 }
 }
 }
 
 function OnGUI(){
 
 if(pressed1 == true){
     if(GUI.Button(Rect(sX - (sX / 2 + 50),sY - (sY / 2 + 50),100,50), "Continue")){
         pressed2 = true;
     }
     if(GUI.Button(Rect(sX - (sX / 2 + 50),sY - (sY / 2 - 10),100,50), "Quit Game")){
         Application.Quit();
     }
 }
 
 }

Please note that this script is also using the size of the screen for positioning so you can probably ignore all the sX's and sY's XD.

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 andrewjm10 · Jul 05, 2013 at 05:22 PM 0
Share

Ok thanks Crazsta, i will try it out in a bit. Im in between classes right now so as soon as i get home i will try it out and see if i can upgrade my script, $$anonymous$$d if i use some of your code as an example for $$anonymous$$e? Yeah my instructor was disappointed i did not make a fully functional pause menu in the time allotted, wish i could learn faster lol.

avatar image Crazsta · Jul 29, 2013 at 11:19 AM 0
Share

hey, sorry for the REALLY late reply as I have been insanely busy, but if you used my code that's fine and I'm glad I could help. If you need any more health don't be afraid to ask

avatar image
0

Answer by Noztradamuz · Jul 05, 2013 at 07:08 PM

Hello, i don't know what are you exactly trying to do, but i have a similar code in one game that pauses the game and shows a little menu to exit or restar the level, check it out, hope it helps.

 //On the Update() function            
 
 if (Input.GetKeyDown(KeyCode.Escape) && !isGamePaused)
             {
                 Time.timeScale = 0;
                 isGamePaused = true;
             }
             else if (Input.GetKeyDown(KeyCode.Escape) && isGamePaused)
             {
                 Time.timeScale = 1;
                 isGamePaused = false;
                 askToRestart = false;
             }
 
 //On the OnGUI() function 
  private void OnGUI()
     {
         if (isGamePaused && gameStarted)
         {
             if (!askToRestart)
             {
                 GUI.Box(new Rect(0, 0, Screen.width, Screen.height), "Pausa");
                 if (GUI.Button(new Rect(Screen.width / 2 - 100, Screen.height / 2 - 10, 90, 20), "Restart"))
                 {
                     askToRestart = true;
                 }
                 if (GUI.Button(new Rect(Screen.width / 2 , Screen.height / 2 - 10, 90, 20), "Exit"))
                 {
                     Application.Quit();
                 }
             }
             if (askToRestart)
             {
                 GUI.Box(new Rect(Screen.width / 2 - 100, Screen.height / 2 - 50, 200, 30), "¿Want to restart?");
                 if (GUI.Button(new Rect(Screen.width / 2 + 5, Screen.height / 2 - 10, 60, 20), "Si"))
                 {                    
                     Application.LoadLevel("GamePlayScene");
                 }
                 if (GUI.Button(new Rect(Screen.width / 2 -65, Screen.height / 2 - 10, 60, 20), "No"))
                 {
                     askToRestart = false;
                 }
             }
         }
 }
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

18 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

Related Questions

Multiple Cars not working 1 Answer

Unity error "scripts exist in multiple locations" 1 Answer

Networking Problem Please Help!!! [IMPORTANT] 0 Answers

my script says OnCollisionEnter() error bce005 and it wont work 3 Answers

Spawn Script Issue 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