Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 Sara · May 13, 2010 at 07:56 PM · buttonsoundpause

Pause: Issues with pausing, resuming, and pressing buttons within pause

It actually worked once, but now I can't get it to work at all. Either the music will still be running or when I press the button I set as resuming, nothing really happens. But when I am in the pause itself, my menu button will not work. I got this code by looking at a few other examples.

var click : AudioClip; var menuSkin : GUISkin; var areaWidth : float; var areaHeight : float; var theTexture : Texture2D;

static var pauseVisible : boolean; private var player : GameObject; private var cam : GameObject;

function Start() {

 // initially hide the pause menu
 pauseVisible = false;
 player = GameObject.Find("First Person Controller");
 cam = GameObject.Find("Camera"); 

}

function Update() {

 if( Input.GetKeyUp( KeyCode.P ) )
 {
         Time.timeScale = 0;
         pauseVisible = true;
         player.GetComponent(SmoothFollow).enabled = false;
         cam.GetComponent(SmoothFollow).enabled = false;
 } 
 else if(Input.GetKeyUp(KeyCode.Space))
 {

         Time.timeScale = 1.0;
         pauseVisible = false;
         player.GetComponent(SmoothFollow).enabled = true;
         cam.GetComponent(SmoothFollow).enabled = true;
 }

}

function OnGUI () { GUI.skin = menuSkin;

 if(pauseVisible)
 {
     GUI.color = Color.white;
     GUI.color.a = 0.5;
     GUI.DrawTexture(Rect(0, 0, Screen.width, Screen.height), theTexture);


     var ScreenX = ((Screen.width * 0.5) - (areaWidth * 0.5));
     var ScreenY = ((Screen.height * 0.5) - (areaHeight * 0.5));


     GUILayout.BeginArea(Rect(ScreenX, ScreenY, areaWidth, areaHeight));

     GUILayout.Box("Pause Menu");    

     if(GUILayout.Button("Main Menu"))
     {
         Application.LoadLevel(7);
     }
     if (GUILayout.Button("Quit")) 
     {
         Application.Quit();
     }
     GUILayout.Label("Press space bar to resume!");

     GUILayout.EndArea();
 }    

} @script RequireComponent (AudioSource)

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
-2

Answer by sandolkakos · Jul 10, 2010 at 04:27 AM

when you use the Time.timeScale = 0, then all Functions stop all your actions, "except Function OnGUI".

then make this:

in Function Update, use this to call the Pause state:

if( Input.GetKeyUp( KeyCode.P ) )
{
        Time.timeScale = 0;
        pauseVisible = true;
        player.GetComponent(SmoothFollow).enabled = false;
        cam.GetComponent(SmoothFollow).enabled = false;
} 

and in Function OnGUI, use this, to unPause state:

if(Input.GetKeyUp(KeyCode.Space)) {

     Time.timeScale = 1.0;
     pauseVisible = false;
     player.GetComponent(SmoothFollow).enabled = true;
     cam.GetComponent(SmoothFollow).enabled = true;

}

i am not an expert, but i think that this fix your problem ;)

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 qJake · Jul 10, 2010 at 04:53 AM 0
Share

No. Input functions, and Update() still runs when TimeScale is = 0. The only thing that changes is the Time (deltaTime, etc), as well as any rigidbodies (since they rely on time, as well). All input functions inside Update will still run, in fact, do not move the Input check to the OnGUI() function. You shouldn't ever check for input in the OnGUI() function unless absolutely necessary (and unless you know how to check for the correct event).

avatar image
0

Answer by Ravi 1 · Nov 09, 2010 at 04:35 PM

Hello if you have not got the answer yet, please go through this post. I have made a package in order to solve this problem. It might help you.

How to pause game

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

No one has followed this question yet.

Related Questions

Play a video ingame by clickin on gameobject 3 Answers

How to ignore Submit button when coming out of pause menu? 0 Answers

Problem with stopping audio? 1 Answer

Unable to click UI Button (Unity 4.6) when TimeScale is 0 1 Answer

pause and restart button on android 1 Answer


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