Answers for "CountDown Unity"

C#
3

countdown timer c# unity

function Update()
 {
     timeLeft -= Time.deltaTime;
     if ( timeLeft < 0 )
     {
         GameOver();
     }
 }
Posted by: Guest on March-11-2021
0

countdown script in unity

using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class  Timer : MonoBehaviour
{
    public int timeLeft = 20;
    public Text countdownText;
    GameObject timeuptext;
    GameObject timeend;
    public int timeCountdownPlays;
    public AudioClip CountDownSound;
    public AudioSource SoundSource;
    

    
    void Start()
    {
        timeuptext = GameObject.Find("TimeUp");
        timeuptext.SetActive(false);
        timeend = GameObject.Find("Timer Text");
        StartCoroutine("LoseTime");
        SoundSource.clip = CountDownSound;
    }

  
    void Update()
    {
       
        countdownText.text = ("" + timeLeft);
            

        if (timeLeft <= 0)
        {
            timeuptext.SetActive(true);
            timeend.GetComponent<Text>().enabled = false;
            
        }

        if (timeLeft == timeCountdownPlays)
        {
            SoundSource.Play();
        }
            
            
        
      
       
    }

    IEnumerator LoseTime()
    {
        while (true)
        {
            yield return new WaitForSeconds(1);
            timeLeft--;
        }
    }
}
Posted by: Guest on March-11-2020
0

CountDown Unity

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Timer : MonoBehaviour
{
    public float timeRemaining = 10;

    void Update()
    {
        if (timeRemaining > 0)
        {
            timeRemaining -= Time.deltaTime;
        }
    }
}Copied!
Posted by: Guest on October-22-2021

C# Answers by Framework

Browse Popular Code Answers by Language