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 Kupo_01 · Sep 30, 2014 at 03:51 AM · c#menupause

Problems with pause menu displaying items and stopping player movement

I have a script that acts as a pause menu and is supposed to completely pause the game, but I'm currently having a problem with it. It stops animations and such, but does not stop the player from looking. Also, the options menu will not show when it is clicked and the resume button does not work. I'm not sure, but the quit button could also be non functional as well, I just haven't built my game to test it.

Can someone help out? Here is the code: http://pastebin.com/yqN9Tb8i

EDIT: The resume and quit buttons now work. I don't know what I did, but it works now. The only problem I'm having now is being able to move the mouse to look while paused.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Addyarb · Sep 30, 2014 at 04:06 AM

Shouldn't you have some sort of bool change if the player hits escape? Something like:

  if (Input.GetKeyDown(KeyCode.Escape))
         {
 paused = !paused;
 
 }


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 phxvyper · Sep 30, 2014 at 04:30 AM 0
Share

He already has this in lines 33 and 43. Although it isn't as effective as your switch, it does the same thing.

avatar image Addyarb · Sep 30, 2014 at 06:52 AM 0
Share

Totally missed it I guess. Never seen it done that way before but I suppose that should work just the same.

avatar image
0

Answer by Nomabond · Sep 30, 2014 at 04:16 AM

You can disable the MouseLook ability by setting the .enabled flag to false, and then again to true on unPause. I was able to test and get it to work with this:

I added the following to the if(!paused) and set them true again in the else if(paused).

  PlayerMouseControllerX.enabled = false;
  PlayerMouseControllerY.enabled = false;



 using UnityEngine;
 using System.Collections;
 
 public class PauseMenu2 : MonoBehaviour
 {
     public bool Paused = false;
     public bool ShowPauseMenu = false;
     public bool ShowOptionsMenu = false;
     public static float SensitivityX = 1f;
     public static float SensitivityY = 1f;
     public MouseLook PlayerMouseControllerX;
     public MouseLook PlayerMouseControllerY;
     
     // Use this for initialization
     void Start()
     {
         Paused = false;
         Time.timeScale = 1;
         Screen.lockCursor = true;
         Screen.showCursor = false;
         ShowPauseMenu = false;
         PlayerMouseControllerX.sensitivityX = SensitivityX;
         PlayerMouseControllerY.sensitivityY = SensitivityY;
     }
     
     // Update is called once per frame
     void Update()
     {
         if (Input.GetKeyDown(KeyCode.Escape))
         {
             if (!Paused)
             {
                 Paused = true;
                 Time.timeScale = 0;
                 Screen.lockCursor = false;
                 Screen.showCursor = true;
                 ShowPauseMenu = true;
                 PlayerMouseControllerX.sensitivityX = 0;
                 PlayerMouseControllerY.sensitivityY = 0;
                 PlayerMouseControllerX.enabled = false;
                 PlayerMouseControllerY.enabled = false;
             }
             else if (Paused)
             {
                 Paused = false;
                 Time.timeScale = 1;
                 Screen.lockCursor = true;
                 Screen.showCursor = false;
                 ShowPauseMenu = false;
                 PlayerMouseControllerX.sensitivityX = SensitivityX;
                 PlayerMouseControllerY.sensitivityY = SensitivityY;
                 PlayerMouseControllerX.enabled = true;
                 PlayerMouseControllerY.enabled = true;
             }
         }
     }
     void OnGUI()
     {
         
         {
             if (ShowPauseMenu)
             {
                 // Make a background box
                 GUI.Box(new Rect(10, 10, 650, 300), "Paused");
                 
                 // Make the resume button
                 if (GUI.Button(new Rect(290, 100, 80, 20), "Resume"))
                 {
                     ShowPauseMenu = false;
                     Time.timeScale = 1;
                     Screen.showCursor = false;
                     Screen.lockCursor = true;
                 }
                 // Make the second button that will kill the process
                 if (GUI.Button(new Rect(290, 200, 80, 20), "Quit"))
                 {
                     Application.Quit();
                 }
                 if (GUI.Button(new Rect(290, 150, 80, 20), "Options"))
                 {
                     ShowPauseMenu = false;
                     ShowOptionsMenu = true;
                 }
             }
             else if (ShowOptionsMenu)
             {
                 GUI.Box(new Rect(10, 10, 650, 300), "Options");
                 GUI.Label(new Rect(150, 200, 150, 20), "Sensitivty X: (" + SensitivityX.ToString() + ")");
                 GUI.Label(new Rect(150, 225, 150, 20), "Sensitivty Y: (" + SensitivityY.ToString() + ")");
                 SensitivityX = GUI.HorizontalSlider(new Rect(200, 200, 150, 20), SensitivityX, 0.1f, 20f);
                 SensitivityY = GUI.HorizontalSlider(new Rect(200, 225, 150, 20), SensitivityY, 0.1f, 20f);
                 //If the "Return" button is pressed, go back to the main menu
                 if (GUI.Button(new Rect(209, 100, 80, 20), "Return"))
                 {
                     ShowPauseMenu = true;
                     ShowOptionsMenu = false;
                 }
             }
         }
     }
 }




Comment
Add comment · Show 1 · 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 Kupo_01 · Sep 30, 2014 at 04:38 AM 1
Share

This is excellent, thank you.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Bool wont change... #C 1 Answer

Pause Menu Text Not Rendering 0 Answers

Problem with Pause Menu because of WaitForSeconds 1 Answer

Multiple Cars not working 1 Answer

How to make a pause menu in c#? 5 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