Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 nabiljoe · Aug 11, 2015 at 01:51 AM · errortagstimescale

Freeze game using timer from start, then resume play when click the button. It is possible ?

Hello everyone. I'm trying to make the game freeze from start using time. Show the information for player to read then player can click button "Ok" to start the game. But game still freeze after button "Ok" is pressed. Thanks for anyone who help me. Here is my code.

 using UnityEngine;
 using System.Collections;
 
 public class MissionPause : MonoBehaviour 
 {
     public Canvas missionCanvas;
     bool missionPanel = true;
 
     public float Timer = 3f;
     
     void  Start ()
     {
         Timer = Time.time + Timer;
     }
     
     void  Update ()
     {
         if (Timer < Time.time) 
         { 
             Time.timeScale = 0;
         }
     }
 
     public void ResumeGame()
     {
         if (missionPanel == true)
         {
         missionPanel = false;
         missionCanvas.enabled = false;
         Time.timeScale = 1 ;
         }
     }
 
 }
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

1 Reply

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

Answer by allenallenallen · Aug 11, 2015 at 01:53 AM

ResumeGame isn't even being called.

And in your Update, Timer < Time.time should be Timer > Time.time. Otherwise, it would continue to freeze forever.

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 nabiljoe · Aug 11, 2015 at 11:01 PM 0
Share

Thank you for faster reply. But I already done it. The game still freeze after i press button "Ok". Any other idea ?

avatar image allenallenallen · Aug 12, 2015 at 03:24 AM 1
Share

Oh shoot, I forgot about timeScale. You see, if timeScale = 0, then void Update won't be called anymore.

I think it's best to use this:

http://docs.unity3d.com/ScriptReference/$$anonymous$$onoBehaviour.Invoke.html

 public float timer = 3f;
 
 void Start(){
     Invoke("UnPause", timer);
     Time.timeScale = 0;
 
 }

avatar image Eno-Khaon · Aug 12, 2015 at 03:34 AM 0
Share

Hehe, yep!

Time.time is scaled by Time.timeScale, so if the timeScale is 0, you'll never see three seconds pass. On the other hand, there are still other options available in Time, such as Time.unscaledTime or Time.realTimeSinceStartup (where no $$anonymous$$imum framerate will be enforced).

avatar image nabiljoe · Aug 12, 2015 at 10:17 AM 0
Share

Thank you everyone for great tips. I get my solution. Here is my new code.

 using UnityEngine;
 using System.Collections;
 
 public class $$anonymous$$issionPause : $$anonymous$$onoBehaviour 
 {
     public Canvas missionCanvas;
     bool missionPanel = true;
 
     public float timer = 3f;
 
     void  Start ()
     {
         Invoke ("PauseGame",timer);
     }
 
     void PauseGame()
     {
         Time.timeScale = 0 ;
     }
 
     public void ResumeGame()
     {
         if (missionPanel == true)
         {
         missionPanel = false;
         missionCanvas.enabled = false;
         Time.timeScale = 1 ;
         }
     }
 
 }
avatar image nabiljoe · Aug 12, 2015 at 10:50 AM 0
Share

ohhh..ok thank you for convert it.

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

Pause gameobjects with tag? 2 Answers

Lots of !IsFinite() Errors and FPS crawling to a halt - How to debug? 1 Answer

Why?? MissingComponentException: 2 Answers

Code error Javascript GUI text 0 Answers

Ontriggerenter not working 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