Search Unity

  1. If you have experience with import & exporting custom (.unitypackage) packages, please help complete a survey (open until May 15, 2024).
    Dismiss Notice
  2. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice

UnifyCommunity PauseMenu

Discussion in 'Immediate Mode GUI (IMGUI)' started by Deleted User, Jan 16, 2011.

  1. Deleted User

    Deleted User

    Guest

    Why not just comment out or remove the call to Pause in Start?

    I have another version somewhere where it's configurable (just added a public variable startPaused and then check if that value is true before calling Start), maybe in the version on http://github.com/technicat but if you never want to start paused, might as well just not have Start call the pause function.
     
  2. eleynta

    eleynta

    Joined:
    Mar 20, 2013
    Posts:
    3
    technicat: If I remove it completely, it still freezes the game but offers no menu to get out of it. The sepia filter remains in place and the character controls remain frozen.
     
  3. Deleted User

    Deleted User

    Guest

    Looking at the Javascript version on the wiki, if you remove the call to PauseGame in the Start function it doesn't do anything else besides setting some variables, so something else is going on, either you've changed the script or maybe have more than one of them in the game. I suggest removing the script and starting over and if you don't understand how the script works, this might help - http://drupal.technicat.com/games/unity/unitygui/pausemenu.html (and if you're new to Unity scripting make sure you read the Scripting Reference on Start and other callbacks)
     
  4. DaltonShimerda

    DaltonShimerda

    Joined:
    Mar 19, 2014
    Posts:
    1
    Hey. I am making a open world survival and saw your script. I used it and put it on my first person controllers camera and when I press Esc it all works except for when I go to the options menu, the mouse disappears and I cant do anything. But when I press Esc it goes back to the menu with the continue, option, and credits. Cam someone please help. Thank you.
     
  5. Deleted User

    Deleted User

    Guest

  6. AaronC

    AaronC

    Joined:
    Mar 6, 2006
    Posts:
    3,552
    technicat does this work for you if you start in fullscreen mode?
     
    Last edited: Nov 18, 2014
  7. Deleted User

    Deleted User

    Guest

    I haven't used it in quite a while, but I think it worked in fullscreen, can't say for sure.
     
  8. Unnatural Selection

    Unnatural Selection

    Joined:
    Jun 12, 2015
    Posts:
    6
    I am trying to make a space game and add a pause menu to it using this script. When I pause the game, the spaceship still moves. I tried fixing it myself by adding a paused variable in several place but so far it hasn't worked(The places where I put them is the Start function, PauseGame function, and UnPauseGame function). How I expected it to work was whenever the user pauses the game, I would set the paused variable to true and when I unpause it is set to false. Then I would have the movement restricted by an
    Code (JavaScript):
    1. if (paused === false){
    2.  
    3. }
    Here is the space flight script:
    Code (JavaScript):
    1. //Didn't use pragma strict because it gave me errors
    2. private var ship_top_speed : float = 2.0;
    3. var ship_speed : float = 0.0;
    4. var Turn = 50;
    5.  
    6. function Update () {
    7.         var controller : CharacterController = GetComponent (CharacterController);
    8.         //forward = transform.TransformDirection(Vector3.forward); //This doesn't work, may be useful example though
    9.             controller.Move(this.gameObject.transform.forward * ship_speed);
    10.             transform.Rotate(Vector3.up * Turn * Input.GetAxis("Horizontal") * Time.deltaTime); //Turn
    11.      
    12.         //Speed up
    13.         if (Input.GetKey("w")){
    14.             if (ship_speed < ship_top_speed){
    15.                 ship_speed += 0.01;
    16.                 if (ship_speed > ship_top_speed){
    17.                     ship_speed = ship_top_speed;
    18.                 }
    19.                 }
    20.         }
    21.      
    22.         //slow down
    23.         if (Input.GetKeyDown("s")){
    24.             if (ship_speed > 0.0){
    25.                 ship_speed -= 0.2;
    26.                 if (ship_speed < 0.0){
    27.                     ship_speed = 0.0;
    28.                 }
    29.             }
    30.         }
    31. }
    The ship doesn't turn when the game is paused, but it still moves forward(which I obviously don't want...)

    To reiterate, when my game is paused my spaceship keeps going forward and I can't find a solution.
     
  9. Deleted User

    Deleted User

    Guest

    I don't see in the script where you actually check your pause variable, but in any case, if you look at the pause script, you can see that it pauses the game by setting Time.deltaTime to zero (in fact, there should be an IsPaused function there that just checks that), and the Unity script reference explains how that affects game time. Just looking at your Update function, you can see how a Time.deltaTime will nullify your rotation code, but is not a factor in the rest of your code, so no surprise there.
     
  10. Unnatural Selection

    Unnatural Selection

    Joined:
    Jun 12, 2015
    Posts:
    6
    I showed you the version where I didn't check the paused variable because the version of the script where I tried to check it, it didn't work. That's why it has nothing about the variable.

    Here's where I DID try to check the paused variable.
    Code (JavaScript):
    1. //Didn't use pragma strict because it gave me errors
    2. private var ship_top_speed : float = 2.0;
    3. var ship_speed : float = 0.0;
    4. var Turn = 50;
    5. public var paused:boolean;
    6. private var shippause : float = ship_speed;
    7.  
    8. function Update () {
    9.         if(paused === true){
    10.             shippause = ship_speed;
    11.             while (paused === true){
    12.                 ship_speed = 0.0;
    13.             }
    14.         }
    15.         else{
    16.             var controller : CharacterController = GetComponent (CharacterController);
    17.             //forward = transform.TransformDirection(Vector3.forward); //This doesn't work, may be useful example though
    18.                 controller.Move(this.gameObject.transform.forward * ship_speed);
    19.                 transform.Rotate(Vector3.up * Turn * Input.GetAxis("Horizontal") * Time.deltaTime); //Turn
    20.            
    21.             //Speed up
    22.             if (Input.GetKey("w")){
    23.                 if (ship_speed < ship_top_speed){
    24.                     ship_speed += 0.01;
    25.                     if (ship_speed > ship_top_speed){
    26.                         ship_speed = ship_top_speed;
    27.                     }
    28.                     }
    29.             }
    30.            
    31.             //slow down
    32.             if (Input.GetKeyDown("s")){
    33.                 if (ship_speed > 0.0){
    34.                     ship_speed -= 0.2;
    35.                     if (ship_speed < 0.0){
    36.                         ship_speed = 0.0;
    37.                     }
    38.                 }
    39.             }
    40.         }
    41. }
    I redefined the paused variable on this script because for some reason it was giving me errors even though I set it as public. Also, sorry if I just missed something simple. I am new to coding with JS and Unity.
     
  11. Nathan1258

    Nathan1258

    Joined:
    Jan 11, 2016
    Posts:
    11
    Hi, I have just recently found your creation and i think it's amazing! Thanks! I was just wondering if there is anyway on making the buttons bigger since they're really small? I'm using the C# version, Thanks

    Nathan
     
  12. Deleted User

    Deleted User

    Guest

    I'm glad this thing is still working! However, I didn't write the C# version on the wiki, and while I usually recommend trying to understand the script and reading the API doc, this stuff is obsolete and your time is probably better spent learning the new Unity GUI system. Nevertheless, this can still be a good exercise in reading code and what you can do is search the code for anything that looks like it's setting a size. For example, the call to BeginPage looks like it's specifying the size of the menu and you can try tweaking it.
     
  13. Nathan1258

    Nathan1258

    Joined:
    Jan 11, 2016
    Posts:
    11
    Okay, Thanks...... I got it ;-)