Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 M4HDI_ · Feb 19, 2021 at 12:31 AM · unity 2dtimercountdown

How can add “Warm up” in unity 2d game?

Hi everyone! I want add "Warmup" to my game like Counter strike Warmup. I want that after 30 sec game start and restart player to original position and there is not timer anymore in the game. How can I Do? I use this line too but not working:

     if (cuurentTime == 0)
     {
         SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
     }

but is not working. I use this cod:

 public class TimerCountDown : MonoBehaviour
 {
     float cuurentTime = 0f;
     float startingTime = 30f;
 
     [SerializeField] Text CountDownText;
     
     void Start()
     {
         cuurentTime = startingTime;
 
     }
 
     void Update()
     {
 
         cuurentTime -= 1 * Time.deltaTime;
         CountDownText.text = cuurentTime.ToString("0");
 
         if (cuurentTime <= 0)
         {
             cuurentTime = 0;
         }
        
     }
      
 }


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 jackmw94 · Feb 19, 2021 at 09:24 AM 0
Share

What sort of not working? Does it count down? Does it not do anything at 0?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by esparow · Feb 19, 2021 at 10:02 AM

this method would be better for a 2d game.

 using System.Collections;
 using UnityEngine;
 
 public class TimerCountDown : MonoBehaviour
 {
 
     private void Start()
     {
         StartCoroutine(StopAndStartGame()); 
     }
 
     IEnumerator StopAndStartGame()
     {
         Time.timeScale = 0;       // for stop game
 
         yield return new WaitForSecondsRealtime(30); // wait 30 second (realtime.. Because game is stoped.)
 
         Time.timeScale = 1;      // for start game
     }
 }

OR

 using UnityEngine;
 using UnityEngine.UI;
 
 public class TimerCountDown : MonoBehaviour
 {
 
     float counter;
 
     [SerializeField]
     Text textCounter ;
 
     bool warmupOn;
 
     private void Start()
     {
         counter = 30;
         warmupOn = true;
     }
     private void Update()
     {
 
         if (warmupOn == true)
         {
             counter -= Time.deltaTime;
             textCounter.text = Mathf.Ceil(counter).ToString();
             Debug.Log("starting");
 
             if (counter == 0 || counter < 0)
             {
                 Debug.Log("stoped");
                 warmupOn = false;
 
                 // Load Scene or Your Restart Method.
             }
         }
 
     }
 
 }

Comment
Add comment · 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 AbandonedCrypt · Feb 19, 2021 at 10:09 AM 2
Share

This won't allow the game to run normally during warmup. It will much rather freeze everything for 30 seconds which is not what OP is asking for.

avatar image M4HDI_ · Feb 19, 2021 at 04:14 PM 0
Share

Hi. Tanks for your answer. but I dont want the game to freeze. i want the player to be able to play for 30 sec but then the player returns to the original location and play normal.

avatar image esparow M4HDI_ · Feb 19, 2021 at 05:35 PM 2
Share

ok. you try 2. script.

avatar image M4HDI_ esparow · Feb 26, 2021 at 01:30 AM 0
Share

Tnx. Its working.

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

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

Related Questions

countdown timer starts from the begining when i reLaunch the app 1 Answer

Start timer with trigger 1 Answer

How to stop the countdown timer when I have collected all the coins? 2 Answers

I want to pick up objects to increase timer. 2 Answers

how to Subtract string from TimeSpan 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