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 benjimazza · Nov 13, 2011 at 01:19 PM · guitexturepause

Making a pause Menu

General question, I have seen quite alot of people asking if there can be a way to make a Pause screen, Then i have seen people answer with the answer create a new scene and GUI buttons and Things on to it But it wouldn't work because it would reset the Game right??,, my question is Couldn't i just make a GUI texture that That activates when i press like the button "M" or something to bring up the GUITexture with like a map and a little red dot to show where i am ??,, then press "M" again to deactivate it :/ Sorry if this question doesn't make sense but it did in my head :P

Comment
Add comment · Show 1
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 FLASHDENMARK · Nov 13, 2011 at 01:24 PM 0
Share

That is the right way of doing it. You were properly thinking about the main menu. For a main menu the(most correct) way would properly be to create a new scene, but for a pause menu you would just set the Time.timeScale to zero and add some GUIs on the screen ;)

5 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by nastasache · Nov 17, 2011 at 11:06 PM

Short answer: change the name of the 'PauseMenu' function both in line 29 and 24.

Long answer: If you are not a coder at all (not so difficult to become one) I will try to learn you how to deal with the errors: when you have an error, pay attention to the most important information: line and character position where error was. For example "(Line 29,10)" mean that there is a problem at line 29 on the script, starting with character number 10, aka 'P'. Look for the string started there with 'P'. This is 'PauseMenu'. So that it's something strange with this string. The probably you must to change it. But where? (there is 3 occurrences of 'PauseMenu' in the script: first one at line 4; second one at line 24 and last one at line 29 where you have the error). The tip is to look what the 'PauseMenu' mean at line 29. It's a function, because have '()' along. Where this function it's called / used? Here you must to investigate a bit what 'PauseMenu' mean at line 4 and at line 24. At line 4 doesn't look like a function; it's a name of the object; so probably you don't want to change this (you maybe use this as name to refer it from other scripts). But in line 24? There looks as parameter of another function - named "GUILayout.Window ()", respectively the paramenter #3. Then, since the "GUILayout" it's an Unity thing, go to Unity documentation and search for "GUILayout.Window" (http://unity3d.com/support/documentation/ScriptReference/GUILayout.Window.html). You will discover there a line:

static function Window (id : int, screenRect : Rect, func : GUI.WindowFunction, text : String, : ) : Rect

The function name is 'Window'; The #3 parameter is "func : GUI.WindowFunction" (func=it's a function). Now, you have the confirmation: 'PauseMenu' on line 24 it's name of a function. What this mean? Mean that on line 24, you call the function defined at line 29. And looks like the engine don't like you use the current name of the function. Just change it name, in both places: where function are declared; and where function are called (for example, to 'ShowPauseMenu'):

Line 24: GUILayout.Window(0, windowRect, ShowPauseMenu,

Line 29: void ShowPauseMenu(int windowPause) {

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 benjimazza · Nov 18, 2011 at 11:50 AM 0
Share

Hey man cheers for taking the time to explain errors and stuff to me should make it a hell of a lot simpler now :)

avatar image
2

Answer by nastasache · Nov 13, 2011 at 02:58 PM

It would not reset the Game if you use an object with DontDestroyOnLoad() and use this object during of game play:

Script: Pause.js attached to a Pause object in Pause scene:

 static var gamePaused : boolean = false;

 function Awake() {
   DontDestroyOnLoad(this);
 }

 function Start() {
     Application.LoadLevel("Level");
 }
 
 function OnGUI () {
    if(gamePaused) {
       GUILayout.Label ("GUI buttons here");
    }
 }
 
 function LateUpdate () {
    if(Input.GetKeyUp(KeyCode.M)){

       if(gamePaused) {

          Time.timeScale = 1.0;
          gamePaused = false;         
 
       } else {
 
             Time.timeScale = 0.0;
             gamePaused = true;
 
       }
    }
    Debug.Log("gamePaused = " + gamePaused);    
 }



Script: Level.js attached to a Level object in Level scene:

 function Start () {
     gameState = FindObjectOfType(Pause);
     gameState.gamePaused = false;
 }

 function Update () {
     Debug.Log ("Level is running, Time.time is = " + Time.time);
 }

Add Level scene to the Build Settings, start the game with Pause scene and watch the log.

Comment
Add comment · Show 3 · 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 Wentzel · Nov 13, 2011 at 03:05 PM 0
Share

There go's my effort! Nice nastasache.

avatar image nastasache · Nov 13, 2011 at 04:42 PM 0
Share

Sorry, Wentzel, I did not want to overlap the efforts. I thought you finished the post and I just completed how to pause without resseting game. Please post your version if you work on. I am newbie in Unity and I have to learn also if more answers here. Thanks.

avatar image Wentzel · Nov 13, 2011 at 05:15 PM 0
Share

No i meant it like a joke lol. Your solution works better :P

avatar image
1

Answer by vozochris_1 · Nov 13, 2011 at 05:42 PM

Why don't you make buttons in a Window instead of just buttons? Well, I don't know javascript, I will write in C#.

using UnityEngine; using System.Collections;

public class PauseMenu : MonoBehaviour {

 public Rect windowRect = new Rect(295,175,0,0);
 public bool gamePaused = false;

 void Update(){
 if(Input.GetKeyUp(KeyCode.M)){
     if(gamePaused){
         gamePaused = false;
         Time.timeScale = 1.0f;
     } else {
         gamePaused = true;
         Time.timeScale = 0.0f;}
     }
 }

 void OnGUI(){

     if (gamePaused){
         Time.timeScale = 0.0f;
         GUILayout.Window(0, windowRect, PauseMenu,
             "Game Paused", GUILayout.Width(100));
     }
 }

 void PauseMenu(int windowPause) {
     if (GUILayout.Button("Resume")){
         Time.timeScale = 1.0f;
         gamePaused = false;

     }
 }

}


It will make a window with name "Game Paused" and 1 button "Resume" in window appear. You can either press M either "Resume" button to continue. You can Add any GUILayout's in window at "void PauseMenu(int windowPause)".

Comment
Add comment · Show 12 · 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 benjimazza · Nov 14, 2011 at 10:05 PM 0
Share

There are a couple of errors in this code :/

avatar image vozochris_1 · Nov 14, 2011 at 10:07 PM 0
Share

Errors? There are no errors, I tested it :| ... by the way it's C# not javascript. And I use this, same code in my current game which is under development, and it works fine

avatar image benjimazza · Nov 15, 2011 at 05:45 PM 0
Share

Well it gives me two errors When i use it this first one is Assets/Pause$$anonymous$$enu.cs(30,6): error CS0542: `Pause$$anonymous$$enu.Pause$$anonymous$$enu(int)': member names cannot be the same as their enclosing type

and the second one is Assets/Pause$$anonymous$$enu.cs(41,1): error CS8025: Parsing error ??

avatar image _AinSoph_ · Nov 15, 2011 at 07:15 PM 0
Share

The parsing error is because of a missing "}" before the OnGUI() function. The other error, the compiller has already given the cause: change the name of Pause$$anonymous$$enu function to something else and it will work.

avatar image benjimazza · Nov 17, 2011 at 09:02 PM 1
Share

I keep getting this error Assets/Scripts/Pause$$anonymous$$enu.cs(29,10): error CS0542: `Pause$$anonymous$$enu.Pause$$anonymous$$enu(int)': member names cannot be the same as their enclosing type

Show more comments
avatar image
0

Answer by syclamoth · Nov 13, 2011 at 01:35 PM

No, there is absolutely no reason why you can't just draw some gui elements on the screen, like a minimap and some buttons. That's what I do, and it works just fine! I don't know about all this talk of making new scenes full of gui elements- as you say, that would reset the game (and you don't want that- it's a pause button not a reset button)

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 benjimazza · Nov 14, 2011 at 09:55 PM 0
Share

So how would i go about doing this ??

avatar image
0

Answer by Wentzel · Nov 13, 2011 at 02:24 PM

As @ OrangeLightning said : Time.timeScale would work fine.

var paused : boolean = false;

function Update () {

if(Input.GetKeyUp(KeyCode.M)){ if(!Paused){ Time.timeScale = 0; paused = true; } } }

As for the GUI buttons.

var MyTexture : Texture;

function OnGUI(){ GUI.Box(Rect(250,50,300,400),"Menu");

if(GUI.Button(Rect(360,100,80,20),"Resume")){ PauseScript.paused = false }

if(GUI.Button(Rect(360,130,80,20),"Quit")){ Application.Quit(); } }

Comment
Add comment · Show 5 · 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 syclamoth · Nov 13, 2011 at 02:28 PM 0
Share

Can you... format that a bit better?

avatar image FLASHDENMARK · Nov 13, 2011 at 02:41 PM 0
Share

Yes, honey...

avatar image Wentzel · Nov 13, 2011 at 02:42 PM 0
Share

Oh yeah sorry.....lol Btw how can i upload an avatar ?

avatar image syclamoth · Nov 13, 2011 at 02:44 PM 0
Share

Thanks, Orange, or whoever it was...

avatar image FLASHDENMARK · Nov 13, 2011 at 06:23 PM 0
Share

No, problem :)

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

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Way to have a pause and play texture in same GUI texture? 0 Answers

GUI.DrawTexture not working? (nothing shows up) 1 Answer

Touchscreen for unity 2 Answers

water mark texture 0 Answers

Wearied Error 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