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 rhbrr5hrfgdfgw · Jul 15, 2013 at 06:02 PM · pausestuck

Pause menu make unity stuck

Sometimes the pause menu stuck unity and sometimes not, this is my script:

 using UnityEngine;
 using System.Collections;
 
 public class Pause : MonoBehaviour {
     
     bool pressedEscape = true;
 
     void Start () {
         Screen.showCursor = false;
     }
     
     void Update () {
                 if(Input.GetKeyUp(KeyCode.Escape) && !pressedEscape){
                 Screen.showCursor = false;
                 pressedEscape = true;
                 Time.timeScale = 1;
                 GameObject.Find("First Person Controller").GetComponent<MouseLook>().enabled = true;
         }else if(Input.GetKeyUp(KeyCode.Escape) && pressedEscape){
             pressedEscape = false;
             Screen.showCursor = true;
             Time.timeScale = 0;
             GameObject.Find("First Person Controller").GetComponent<MouseLook>().enabled = false;
                 }
         }
     void OnGUI(){
             if(!pressedEscape){
             if(GUI.Button(new Rect(300, 300, 200, 50), "Attachments")){
                     
             }    
         }
     }
 }

Whats the problem with this script?, thanks in advance

Comment
Add comment · Show 2
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 PAEvenson · Jul 15, 2013 at 06:53 PM 0
Share

explain stuck...Does your cursor show up/and or can you move your camera?

avatar image rhbrr5hrfgdfgw · Jul 15, 2013 at 10:46 PM 0
Share

By saying stuck i mean the program is not responding, and i dont know how to explain it but its like a boolean when starting the game the "boolean" setting to true or false and by this "boolean" the game getting stuck/not getting stuck (there isn't really boolean its just an example)

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by SubatomicHero · Jul 16, 2013 at 09:54 AM

To make this a little simpler to read see if these changes help:

 public class Pause : MonoBehaviour {
 
     bool pressedEscape = false; // ..because we havent pressed it yet
 
     void Start(){
         Screen.showCursor = false;
     }
 
     void Update(){
         if (Input.GetKeyUp(KeyCode.Escape){
             pressedEscape = !pressedEscape;
             // if it is true its now false
             // if it is false its now true;
         }

         // we then check the value of pressedEscape
         if (pressedEscape){ // pressedEscape is true so pause
             changePauseStatus(true, 0, false);
         } else { // pressedEscape must be false
             changePauseStatus(false, 1, true);
         }
     }
 
     void changePauseStatus(bool showCursor, int timeScale, bool fpsEnabled){
         Screen.showCursor = showCursor;
         Time.timeScale = timeScale;
         GameObject.Find("First Person Controller").GetComponent<MouseLook>().enabled = fpsEnabled;
     }

If you still have crashing issues I suspect its the GameObject.Find lines not finding the gameobject.....maybe. Sometimes simplifying your code can iron out small bugs in it :D

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 rhbrr5hrfgdfgw · Jul 16, 2013 at 12:40 PM 0
Share

I've already fixed it, if some one want to know how: its look like changing the zero in the code to 0.00001f make it not crash.

avatar image amphoterik · Jul 16, 2013 at 12:57 PM 0
Share

Please update your original question with the fixed code if you resolved it. This will help people in the future.

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

How to export MMD model to Unity? 0 Answers

A node in a childnode? 1 Answer

Object moves out of own collider. 3 Answers

Very little, but very heavy script problem. 0 Answers

Blender Animation Problems 3 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