Advertisement
Guest User

Untitled

a guest
Dec 9th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.99 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Countdown : MonoBehaviour
  6. {
  7.     public float time = 60.0f;
  8.     private float targetTime;
  9.     private UnityEngine.UI.Text timer;
  10.  
  11.     void Start()
  12.     {
  13.         timer = GetComponent<UnityEngine.UI.Text>();
  14.         targetTime = time;
  15.     }
  16.  
  17.     void Update()
  18.     {
  19.  
  20.         if (targetTime >= 0)
  21.         {
  22.             targetTime -= Time.deltaTime;
  23.             int rounded = (int)Mathf.Ceil(targetTime); // Dit convert de float naar een int en rond omhoog af (59.2 word 60 bijv )                                                  
  24.             timer.text = rounded.ToString();
  25.         }
  26.  
  27.         if (targetTime <= 0.0f)
  28.         {
  29.             timerEnded();
  30.         }
  31.  
  32.     }
  33.  
  34.     void timerEnded()
  35.     {
  36.         timer.text = "Done";
  37.         //do your stuff here.
  38.     }
  39.  
  40.     void reset()
  41.     {
  42.         // doe hier round reset shit voor de timer
  43.         targetTime = time;
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement