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 jong · Feb 02, 2013 at 09:42 AM · gamemousepauseclick

pause game

Help!!!

I want to pause my game when after i click the mouse. i can't get it right.

Here's my code:

pragma strict

 private var guiOn = false;
 var wasClicked : boolean;
 var paused : boolean = false;
      
 function OnMouseDown()
 {
     wasClicked = true;
     OnPausedGame();
     Activate();
 }
      
 
 function OnMouseEnter()
 {
     if (wasClicked) 
     {
         Activate();
     }
 }
 
 function Activate()
 {
     guiOn = true;
     OnPausedGame();
     //OnGUI();
 }
 
 function OnGUI()
 {
     if (guiOn)
     GUI.Box(new Rect(0, Screen.height - 50, 300, 100), "test");
 }
 
 function OnPausedGame()
 {
     if (wasClicked)
     {
         if (!paused)
         {
             Time. timeScale = 0;
             paused = true;
             
             OnGUI();
         }
     }
 }
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 Doireth · Feb 02, 2013 at 09:53 AM 1
Share

When you say "can't get it right", what is actually wrong?

avatar image jong · Feb 02, 2013 at 10:18 AM 0
Share

i don't know how to arrange the code that will pause the game. i dont know where to place OnPausedGame to the other functions.

2 Replies

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

Answer by jong · Feb 02, 2013 at 05:52 PM

Can I ask another question?

How can i put an if statement to GUI.button?

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 Doireth · Feb 03, 2013 at 01:30 AM 1
Share

Of course.

 function OnGUI()
 {
     if(GUI.Button(Rect(10,10,150,100), "Pause/UnPause"))
     {
          if(Time.timeScale == 1)
          {
               Time.timeScale = 0;
          }
          else
          {
               Time.timeScale = 1;
          }
     }
 }
avatar image Doireth · Feb 03, 2013 at 05:12 AM 0
Share

I don't see how it was you who answered the question.

avatar image
0

Answer by Doireth · Feb 02, 2013 at 10:23 AM

To pause a game you could simply write

 function Update()
 {
     if(Input.GetButtonDown("Fire1") && Time.timeScale != 0)
     {
         Time.timeScale = 0;
     }
     else
     {
         Time.timeScale = 1;
     }
 }

This is a basic example of pausing. Your code seems somewhat excessive but then again I don't know how your program works.

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 jong · Feb 02, 2013 at 10:43 AM 0
Share

Can i separate this part?

 else
 {
 Time.timeScale = 1;
 }

I want to put it under GUI.button. so when player clicks the button, the game resumes.

sorry i'm still newbie to unity and javascript.

avatar image Doireth · Feb 02, 2013 at 10:46 AM 0
Share

Sure, that's perfectly valid (though you won't use the "else" part if it's no longer part of an if/else statement. Just the "Time.timeScale = 1" bit).

$$anonymous$$y code was merely an example of pausing. It was only meant to illustrate the idea, you should adapt it to your needs.

avatar image jong · Feb 02, 2013 at 10:49 AM 0
Share

Thanks. I understand more now clearly.

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

10 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

Related Questions

How to Disable/Inactive NGUI Button on Game Pause? 0 Answers

Can you pause unity playmode while mouse button is down? 2 Answers

C# moveOnMouseClick Rotation 2 Answers

Play a video ingame by clickin on gameobject 3 Answers

Camera Orbit on Left Click problem 0 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