Advertisement
Guest User

Untitled

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