rengetsu

PD_Timer

Apr 13th, 2018
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.02 KB | None | 0 0
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5.  
  6. public class Timer: MonoBehaviour
  7. {
  8.     public Text timerText; // text variable for our timer time
  9.     public Text scoreText; // text variable for our score bar
  10.     private float startTime; //variable to check than our timer start
  11.     private bool finnished = false; //to check than player finnished
  12.  
  13.     void Start()
  14.     {
  15.         startTime = Time.time;
  16.     }
  17.  
  18.     private void Update()
  19.     {
  20.         if (finnished)
  21.             return;
  22.         //timer settings
  23.         float t = Time.time - startTime; //time gone since our timer starts
  24.  
  25.         string minutes = ((int)t / 60).ToString();
  26.         string seconds = (t % 60).ToString("f0");
  27.  
  28.         timerText.text = minutes + ":" + seconds;
  29.     }
  30.     //Than our player finnishing
  31.     public void Finnish()
  32.     {
  33.         finnished = true;
  34.         //all text gets green
  35.         timerText.color = Color.green;
  36.         scoreText.color = Color.green;
  37.     }
  38. }
Add Comment
Please, Sign In to add comment