Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Countdown : MonoBehaviour
- {
- public float time = 60.0f;
- private float targetTime;
- private UnityEngine.UI.Text timer;
- void Start()
- {
- timer = GetComponent<UnityEngine.UI.Text>();
- targetTime = time;
- }
- void Update()
- {
- if (targetTime >= 0)
- {
- targetTime -= Time.deltaTime;
- int rounded = (int)Mathf.Ceil(targetTime); // Dit convert de float naar een int en rond omhoog af (59.2 word 60 bijv )
- timer.text = rounded.ToString();
- }
- if (targetTime <= 0.0f)
- {
- timerEnded();
- }
- }
- void timerEnded()
- {
- timer.text = "Done";
- //do your stuff here.
- }
- void reset()
- {
- // doe hier round reset shit voor de timer
- targetTime = time;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement