Advertisement
LeeMace

Countdown Timer

Dec 8th, 2022 (edited)
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.47 KB | Gaming | 0 0
  1. //Create timeText in Hierarchy,
  2. //in game manager.cs
  3.  
  4. public TextMeshProUGUI timeText;
  5.     private float timeDown = 30;
  6.    
  7.     public void UpdateTime()
  8.     {
  9.         if(isGameActive)
  10.         {
  11.             timeDown -= Time.deltaTime;
  12.             timeText.text = "Time: " + Mathf.Round(timeDown);
  13.             if(timeDown <= 0)
  14.             {
  15.                 GameOver();
  16.             }
  17.         }
  18.     }
  19.  
  20.     private void Update()
  21.     {
  22.         UpdateTime();
  23.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement