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 Vedant DUlori · Jan 17, 2015 at 06:53 PM · guigameobjecttextpause menupausegame

I can't pause my game? How to make a pause menu in C# for SPace Shooter type Game?

I searched on Youtube and Unity Answers about the pause menu but the only problem is that the game objects of the game don't stop and continue if it paused. I also am trying to create a pause menu once the user clicks on pause button. But, i am enable to do it. Following is my code:

using UnityEngine; using System.Collections;

public class PauseGame : MonoBehaviour {

 public GameObject Gameobject=null;
 public GUISkin layer;
 private Rect windowRect;
 private bool paused = false , waited = true;

 private void Start()
 {
     windowRect = new Rect(Screen.width / 2 - 100, Screen.height / 2 - 100, 500, 500);
 }

 private void waiting()
 {
     if (waited)
             if (Input.GetMouseButtonDown(0) || Input.GetKey (KeyCode.Escape)) {
                 
                 if(paused)
                     paused = false;
                 else
                     paused = true;
         waited = false;
         Invoke("waiting",0.3f);
     }
 }

 private void OnGUI ()
 {
     if (paused)
         windowRect = GUI.Window (0, windowRect, windowFunc, "Game Paused");
 }
 private void windowFunc(int id)
 {
     if (GUILayout.Button("Resume Game")){
         paused = false;        
     }
     if (GUILayout.Button("Restart")) {
         Application.LoadLevel(4);
     }
     if (GUILayout.Button("Main Menu")) {
         Application.LoadLevel(1);
     }
     if (GUILayout.Button("Exit Game")) {
         Application.Quit();
     }
 }

}

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
1

Answer by Steampunk_Droid · Jan 17, 2015 at 07:10 PM

One way to do this in C# is when the game is paused, set Time.timeScale to 0.0f and when it's unpaused reset it to 1.0f... and in all the scripts that you want to pause, instead of using Update() use FixedUpdate()

I know it's a bit of a faff but it worked for me about a week ago when I had the same 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 Vedant DUlori · Jan 23, 2015 at 04:36 PM 0
Share

Thanks, I would definitely try this

avatar image
0

Answer by Reder13 · Jan 17, 2015 at 08:25 PM

how about something like this:

void OnGUI(){

if (GUI.Button (new Rect (Screen.width - 115, 90, 100, 50), pauseText.text)) {

                     if (!paused) {

                             Time.timeScale = 0;
                             paused = true;
                             pauseText.text = "Play";

                                // do whatever you want while paused

                     }

else {

                             Time.timeScale = 1.0f;
                             pauseText.text = "Pause";
                             paused = false;
                             //audio.Play ();
                     }
             }
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 Vedant DUlori · Jan 23, 2015 at 04:37 PM 0
Share

Thanks, I would try this out

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Can't destroy an arrray with GUI Text 1 Answer

text display on touch 1 Answer

How to make text appear when moving next to an object? 3 Answers

Button then instanitates gameobject 1 Answer

Big text field GUI. 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