Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Countdown Timer Animation

Discussion in 'Editor & General Support' started by BenBonkGames, Mar 27, 2019.

  1. BenBonkGames

    BenBonkGames

    Joined:
    Jul 13, 2018
    Posts:
    16
    Hi, so I am working on 2 player platformer race-ish game and want to have a sort of countdown timer before the players can move. I made a coroutine which stops the player from moving for 5 secs while the animation is playing.
    Code (CSharp):
    1.  IEnumerator startMovementIE()
    2.     {
    3.         //play countdown animation
    4.         yield return new WaitForSeconds(5);
    5.         startMovement = true;
    6.     }
    7.  
    However, I'm not sure where to start on the countdown animation, for example how to swap sprites and that stuff, or if I should look at it in a different approach. Any help would be greatly appreciated.
     
  2. BenBonkGames

    BenBonkGames

    Joined:
    Jul 13, 2018
    Posts:
    16
    Hello, I worked this out by making a simple script as shown for a timer if anyone has a similar problem.
    Code (CSharp):
    1. public float currentTime = 0f;
    2.     public float startingTime = 10f;
    3.  
    4.     [SerializeField]Text countdownText;
    5.  
    6.     private void Start()
    7.     {
    8.         currentTime = startingTime;
    9.     }
    10.  
    11.     private void Update()
    12.     {
    13.         currentTime -= 1 * Time.deltaTime;
    14.         countdownText.text = currentTime.ToString("0");
    15.     }