Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 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 Collinbxyz · Jul 20, 2010 at 07:50 PM · pausegui-buttonunpause

Pause Button Script

Hi, I am almost finished my game, but I still want a button to pause and unpause my game. I want it to be a .GUI button if you can. Please help! Thank you!

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 fireDude67 · Dec 12, 2010 at 06:17 PM 0
Share
  • Duplicate of what Julian Glenn just said below

avatar image Artifactx · Mar 14, 2015 at 04:15 PM 0
Share

Here is a tutorial that $$anonymous$$ches you how to do that: http://youtu.be/z5oA-DvVGoo

4 Replies

· Add your reply
  • Sort: 
avatar image
6

Answer by Julian-Glenn · Jul 20, 2010 at 07:54 PM

First search for Pause revealed this:

http://answers.unity3d.com/questions/15262/end-pause-game

Try click on the tag Pause or search as it helps keep the site cleaner :)

Here is a script that creates a pause/continue/quit GUI attach it to the Camera in your scene, or any GameObject with a GUILayer component attached.

var guiSkin: GUISkin; var nativeVerticalResolution = 1200.0; var isPaused : boolean = false;

function Update() {

  if(Input.GetKeyDown("escape") && !isPaused)

{ print("Paused"); Time.timeScale = 0.0; isPaused = true; } else if(Input.GetKeyDown("escape") && isPaused) { print("Unpaused"); Time.timeScale = 1.0; isPaused = false;
} }

function OnGUI () {

 // Set up gui skin
 GUI.skin = guiSkin;

 // Our GUI is laid out for a 1920 x 1200 pixel display (16:10 aspect). The next line makes sure it rescales nicely to other resolutions.
 GUI.matrix = Matrix4x4.TRS (Vector3(0, 0, 0), Quaternion.identity, Vector3 (Screen.height / nativeVerticalResolution, Screen.height / nativeVerticalResolution, 1)); 


 if(isPaused)
 {
   // RenderSettings.fogDensity = 1;
   if(GUI.Button (Rect((Screen.width)/2,480,140,70), "Quit", "button2"))
   {
      print("Quit!");
      Application.Quit();
   }
   if(GUI.Button (Rect((Screen.width)/2,560,140,70), "Restart", "button2"))
   {
      print("Restart");
      Application.LoadLevel("SomeLevelHere");
      Time.timeScale = 1.0;
      isPaused = false;
   }
   if(GUI.Button (Rect((Screen.width)/2,640,140,70), "Continue", "button2"))
   {
      print("Continue");
      Time.timeScale = 1.0;
      isPaused = false;   
   }

}

}

@script AddComponentMenu ("GUI/Pause GUI")

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 luketheboss03 · May 09, 2015 at 03:06 PM 0
Share

When I put the script in the camera and play the game, I get a ton of errors...Please help.alt text

screen-shot-2015-05-09-at-110447-am.png (490.0 kB)
avatar image nurullah us · May 10, 2015 at 12:03 AM 0
Share

hi luketheboss03. As the scripts are put into the camera without playing. There was no mistake, I run and I'm still using the same. :S :S :S

avatar image
-1

Answer by kchrysanthis · Nov 14, 2012 at 07:49 PM

what kinda script is it? Can we get the full code pls =)

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

Answer by Kurt P · Mar 22, 2011 at 08:48 PM

This isn't an answer but you can change whether or not you want to exit the application with the quit button or if you want to make your player go to a main menu all you do is change this part Application.Quit(); and so change it to this Application.LoadLevel("name of main menu here");

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

Answer by nurullah us · May 04, 2015 at 10:36 AM

I hope it helps you :) js coce! Take it into the camera.

 #pragma strict
 var pause : boolean = false;
 function OnGUI()
 
  {
  if (GUI.Button (Rect(Screen.width-55,60,50,50),"Pause"))
 
 
 {
 
 
 if (pause == false)
 { 
 pause = true ;
 Time.timeScale = 1 ;
 
 return;
 }
 
 if (pause == true)
 {
 pause = false;
 Time.timeScale = 0 ;
 return;
 
 }
 }
 }
 
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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

In game pause menu 2 Answers

When i press play it just pauses right after. 6 Answers

How to create a gui button inside an if statement? 1 Answer

Pause Menu - Loading & Quitting 1 Answer

Transitions When Pausing? 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