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 Cdra · Apr 29, 2013 at 03:54 PM · guibuildpauseongui

Pause menu script not working in built game (but works fine in editor)?

My game has a pause menu script (attached to the main camera in every scene) that pauses/unpauses the game when you press Escape and opens the menu too. However, in the built version of the game, it still pauses/unpauses, but the menu doesn't show! How might I fix that? Here's the script (C#), in case it helps you:

 using UnityEngine;
 using System.Collections;
 
 public class PauseMenu : MonoBehaviour {
     public GUISkin guiSkin;
     public float nativeVerticalResolution = 1200.0f;
     private float nativeHorizontalResolution = 1900f;
     private bool isPaused = false;
     public string levelName;
     
     private PlayerStatus status;
     
     void Start() {
         status = GameObject.FindGameObjectWithTag("Player").GetComponent<PlayerStatus>();
     }
     
     void Update() {
         if (Input.GetKeyDown("escape")) {
             print("Paused");
             isPaused = !isPaused;
             Screen.showCursor = isPaused;
             Pause.TogglePaused ();
         }
     }
     
     public void TogglePause() {
         isPaused = !isPaused;
     }
     
     private bool isQuit = false;
      
     void OnGUI (){
         // Set up gui skin
         GUI.skin = guiSkin;
         GUI.matrix = Matrix4x4.TRS (new Vector3(0, 0, 0), Quaternion.identity,  new Vector3 ((float) Screen.width / nativeHorizontalResolution, (float) Screen.height / nativeVerticalResolution, 1f));
         
         if(isPaused) {
             if (!Screen.showCursor) Screen.showCursor = true;
             // RenderSettings.fogDensity = 1;
             GUILayout.BeginArea(new Rect (480, 200, 1000, 1000));{
                 GUILayout.Box ("Game Paused", "Title");
                 
                 if (GUILayout.Button ("Reload Level")) {
                     Application.LoadLevel(levelName);
                     Time.timeScale = 1.0f;
                     isPaused = false;
                     Pause.TogglePaused ();
                 }
             
                 if (GUILayout.Button ( "Open Status Menu")) {
                     status.OpenStatGUI();
                     isPaused = false;
                 }
         
                 CameraControls.invertX = GUILayout.Toggle(CameraControls.invertX, "Invert Camera X Movement", "button");
                 CameraControls.invertY = GUILayout.Toggle(CameraControls.invertY, "Invert Camera Y Movement", "button");
             
                 if (GUILayout.Button ("Return to Game")) {
                     Time.timeScale = 1.0f;
                     isPaused = false;
                     Pause.TogglePaused ();
                 }
             
                 if (GUILayout.Button ("Quit Game")) {
                     //Time.timeScale = 1.0f;
                     isPaused = false;
                     isQuit = true;
                     Pause.TogglePaused ();
                 }
                 
             }GUILayout.EndArea();
 
         } else if (isQuit) {
             GUILayout.BeginArea(new Rect (480, 200, 1000, 1000));
                 GUILayout.Box ("Are you sure?", "Title");
 
                 if (GUILayout.Button ("Quit")) {
                     Time.timeScale = 1.0f;
                     isQuit = false;
                     Pause.TogglePaused ();
                     Application.LoadLevel("mainMenu");
                 }
             
                 if (GUILayout.Button ("Cancel")) {
                     isPaused = true;
                     isQuit = false;
                 }
             GUILayout.EndArea();
         }
     }
 }


Interestingly enough, there's another script that pauses the game and opens a menu (the stats menu mentioned in this script) when you press "L", and that menu works perfectly in the build.

EDIT: I've figured out that this OnGUI is not getting called at all. What could be doing that? I tried making it public, but that didn't change anything either.

Comment
Add comment · Show 4
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 Cdra · Apr 29, 2013 at 04:52 PM 0
Share

I got a Corrupted File Error on level1_data. Could that be it?

avatar image ExTheSea · Apr 29, 2013 at 04:57 PM 0
Share

Yes could be. Try making a new file and then copying the code into the new one.

avatar image Cdra · Apr 29, 2013 at 04:59 PM 0
Share

Looks like the problem might have been a duplicate script name! There was a .js file with the same name (from another package). I also went ahead and tried what you said, and deleted the other script, either way it's working now! Thanks!

avatar image ExTheSea · Apr 29, 2013 at 05:01 PM 0
Share

Good that it works now i will convert my comment to an answer so that you can accept it to mark the question as solved.

1 Reply

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

Answer by ExTheSea · Apr 29, 2013 at 04:36 PM

I don't know if that's the case here but I also once had a problem where my script wasn't working in the build but worked in the the Editor. The problem was that the script got corrupted when i updated to Unity 4. What i did to solve my problem: Create a new Script and copy all the code from the corrupted one in the new one. Then just use the new Script. If you first want to see if that could be the problem make a build in development mode. Then make what normaly executes something inside your pause-script. If a Corrupted File Error appears that could be your problem.

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

14 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

Related Questions

Script using a Pause library causes audio to intermittently cutout. 0 Answers

Distribute terrain in zones 3 Answers

GUI not work after building 1 Answer

Free Gui solutions 2 Answers

Unity 4.7 - OnGUI prevent click/touch through 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