• 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 JakeLeB · Jan 09, 2015 at 02:51 AM · cursorpause menu

Pause Menu (Cursor keeps locking in place)

So I've decided to create a pause menu, before I was using Esc to go straight back to the main menu. I'm still new to creating games but from what I understand this should work.

When the game is set to un-paused the cursor is hidden and locked, when esc is pressed it's unlocked and shown and all works fine, but as soon as I try to press a button I've set the cursor jumps straight to the middle of the screen without being able to click it.

In-game I have a gun that fires on LMB, when I click on Resume/Play the gun fires but freezes due to the Time.timeScale being set to 0f. Is there something I'm doing wrong or could this be caused by another script?

 using UnityEngine;
 using System.Collections;
 
 public class PauseMenu : MonoBehaviour {
 
     public string CurrentMenu;
     public GUISkin _theSkin = null;
     public AudioClip button;
 
     public GameObject WeaponCamera;
 
     void Start () {
         CurrentMenu = "Game";
         Screen.lockCursor = true;
     }
 
     void OnGUI() 
     {
         GUI.skin = _theSkin;
 
         GUI.Label (new Rect(0, 0, 250, 30), Time.timeScale.ToString());
 
         if ( CurrentMenu == "Game") Menu_Game();
         
         if ( CurrentMenu == "Pause") Menu_Pause();
     }
 
     private void Menu_Game()
     {
         if (Input.GetKey(KeyCode.Escape))
         {
                 CurrentMenu = "Pause";
         }
     }
 
     private void Menu_Pause()
     {
         Screen.lockCursor = false;
         Screen.showCursor = true;
         WeaponCamera.GetComponent<Blur>().enabled = true;
         Time.timeScale = 0f;
 
         if(GUI.Button (new Rect (Screen.width / 2 - 75, Screen.height / 2 + 15, 150, 30), "Play", "button"))
         {
             audio.PlayOneShot(button, 0.7F);
             Screen.lockCursor = true;
             Screen.showCursor = false;
             WeaponCamera.GetComponent<Blur>().enabled = false;
             Time.timeScale = 1f;
             CurrentMenu = "Game";
         }
         
 
         if(GUI.Button (new Rect (Screen.width / 2 - 75, Screen.height / 2 + 55, 150, 30), "Settings", "button"))
         {
             audio.PlayOneShot(button, 0.7F);
         }
     }
 
 }
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by SnStarr · Jan 10, 2015 at 11:12 AM

Nothing looks wrong in your script that could be causing this, though there are a few opimizations you could make. This is a common bug in Unity that only happens in the editor and more often happens in the editor if Maximize on Play is not turned on. Everything should work fine once you build the game and run the actual .exe.

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

27 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Mouse Cursor Problem 2 Answers

Unity 5 - pause menu bug 0 Answers

Can anyone translate this to C# (Change cursor appearance) 1 Answer

Lock mouse position with a Rect, possible? 1 Answer

Particle Emitter from moving object to cursor location 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges