• 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
Question by importguru88 · Aug 07, 2016 at 08:40 PM · animationprefabscenepausecountdown

How do I pause everything in the scene until the animation countdown prefabs done counting down in the scene

I have some countdown animations prefabs . I can only play the countdown animations in the scene if I drag the prefab in the scene and click on play . What I am trying to is play all 10 or 5 animation countdown prefab. But I want the scene to pause everything including the player and music until the countdown animations are done counting down in the scene. If have anymore questions just ask me.

Comment

People who like this

0 Show 0
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

3 Replies

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by Cence99 · Aug 07, 2016 at 10:23 PM

From a coder's perspective I would disable all scripts (or all scripts that move things or do the gameplay), freeze rigidbodies, disable audio components etc. until the countdown finished. Then just enable them again.

Comment

People who like this

0 Show 4 · 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 importguru88 · Aug 07, 2016 at 11:08 PM 0
Share

I can disable the scripts. How will do them all at the same time ?

avatar image importguru88 · Aug 07, 2016 at 11:08 PM 0
Share

Do I need to code ? I just want the gameobject to be pause .

avatar image Cence99 · Aug 07, 2016 at 11:50 PM 1
Share

Yes you need to code as this is game logic you'd like to change

avatar image importguru88 Cence99 · Aug 08, 2016 at 12:38 AM 0
Share

Give an example please of a code . Like how I should come at it.

avatar image

Answer by Anhvuive · Aug 08, 2016 at 02:10 PM

You can set timescale = 0 And Run static StartCourotine on static class to countdown and reset timescale = 1 after finish

code demo: using UnityEngine; using System.Collections; using UnityEngine.UI;

 public class Test : MonoBehaviour
 {
 
     void Start()
     {
 
     }
 
     void Update()
     {
         if (Input.GetKeyDown(KeyCode.Space))
         {
             Time.timeScale = 0;
             StartCoroutine(ExtentCountDown.CountDownWithoutTimeScale(1, 10, GetComponent<Text>()));
         }
     }
 }
 
 
 public static class ExtentCountDown
 {
     public static IEnumerator CountDownWithoutTimeScale(int interval, int duration, Text txtView)
     {
         while (true)
         {
             float pauseEndTime = Time.realtimeSinceStartup + duration;
             while (Time.realtimeSinceStartup < pauseEndTime)
             {
                 Debug.Log(Time.realtimeSinceStartup + " : " + pauseEndTime);
                 txtView.text = (pauseEndTime - Time.realtimeSinceStartup).ToString("00");
                 yield return 0;
             }
             Time.timeScale = 1;
             break;
         }
     }
 }
Comment

People who like this

0 Show 0 · 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

Answer by PhantomSarcasm · Aug 08, 2016 at 02:52 PM

there is a way coded. You can spend the whole scene, this stops stop or you can make it that way ma slow pace.

if you use:

 Time.timeScale=0; stop
 
 Time.timeScale=1; play
 
 Time.timeScale=0.5f; half speed

remember that this will stop all animations and corutinas but will not stop the update or fixedupdate.

Comment

People who like this

0 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 importguru88 · Aug 08, 2016 at 04:03 PM 0
Share

Here is my script for the countdown. Where would I be add that code ?

 using UnityEngine;
 using System.Collections;
 
 public class CountDownManager : MonoBehaviour
 {
     //Store the whole countdown objects
     public GameObject[] countDownObjects;
     
     //Define the countdown starting number, it should between 0-9!
     public int startNumber = 3;
     
     //Define the countdown ending number, it should between 0-9!
     public int endNumber = 0;
     
     //Define whether display the "GO!" logo at the end
     public bool displayGoAtTheEnd = true;
     
     //Define when will start to countdown
     public float startAfterSeconds = 0.0f;
     
     //Time counter
     private float myTime = 0.0f;
     
     //Cache the trasform of object
     private Transform myTrans;
     
     //Define the direction , 1 means from less to more, -1 means from more to less.
     private int direction = -1;
     
     //Define acctually countdown objects
     private GameObject[] countdown;
     
     //Define the trigger of spawn countdown object
     private bool canSpawn  = false;
     private int number;
     // Use this for initialization
     void Start ()
     {
         //Cache the transform
         myTrans = transform;
         
         //If the number out of range, tell the user.
         if(startNumber>9 || startNumber<0 || endNumber >9 || endNumber <0){
             print("StartNumber and EndNumber should between 0-9! Please reinput the numbers.");            
         }
         //Make sure the start and end frame is between 0-9 integer
         startNumber = Mathf.Clamp(startNumber,0,9);
         endNumber = Mathf.Clamp(endNumber,0,9);
         
         
         //Define the correct direction
         if( endNumber > startNumber ){
             direction = 1;
         }
         
         number = startNumber;
         //Whether need to show "GO!" at last
         if(displayGoAtTheEnd){
             
             //Define the acctually countdown objects array
             countdown = new GameObject[Mathf.Abs(endNumber - startNumber) + 2];
             for(int i=0 ; i<countdown.Length-1; i++){
                 countdown[i] = countDownObjects[number];
                 number += direction;
             }
             
             //If need to show "GO!" at last , add the "GO!" countdown object to the end of array.
             countdown[ countdown.Length -1 ] = countDownObjects[10];
             
         } else {
             //Define the acctually countdown objects array(do not need to show "GO!")
             countdown = new GameObject[Mathf.Abs(endNumber - startNumber) + 1];
             for(int i=0 ; i<countdown.Length; i++){
                 countdown[i] = countDownObjects[number];
                 number += direction;
             }
         }
         number = 0;
     }
     
     void Update(){
         //Time counter
         myTime+=Time.deltaTime;
         
         //Is it the time to start countdown
         if(myTime >= startAfterSeconds && !canSpawn){
             canSpawn = true;
             myTime =1000000.0f;
         }
         
         //Spawn one countdown object each second by the order
         if(myTime >= 1.0f && canSpawn){
             myTime = 0.0f;
             //If countdown is over, then distroy the object.
             if(number >= countdown.Length){
                 SelfDestroy();
             } else {
                 SpawnCountDown( number );
             }
                 
             number++;
             
         }
     }
     
     //Self destroy function
     void SelfDestroy ()
     {
         Destroy (gameObject);
     }
     
     //Spawn countdown object at current position
     void SpawnCountDown(int number){
         GameObject countNum = Instantiate(countdown[number], myTrans.position,myTrans.rotation) as GameObject;
         countNum.transform.parent = myTrans;
     }
     
 }
avatar image PhantomSarcasm importguru88 · Aug 09, 2016 at 02:07 PM 0
Share

as I said the syntax is to stop all animation and sound itself it is like a pause scena, but this does not stop the Update of a script. could not tell you where to put it, besides not specifically what you want in if ..... this syntax is just a standard code to stop and if quires stop something specific you have to look into that in espesifico for example if music have to put stop ("name gives track"), so you can not help much. sorry

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

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

Related Questions

How do I keep the scene pause until the prefab animations are done counting down in the scene 0 Answers

How do play prefab animation countdown numbers in my scene properly 0 Answers

Save an unpacked prefab 1 Answer

Animations on Instantiated Prefabs not working 0 Answers

Updating a prefab fbx or animation while using version-control is broken 4 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