Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using UnityEngine.UI;
- using System.Collections;
- using System.Collections.Generic;
- public class Timer: MonoBehaviour
- {
- public Text timerText; // text variable for our timer time
- public Text scoreText; // text variable for our score bar
- private float startTime; //variable to check than our timer start
- private bool finnished = false; //to check than player finnished
- void Start()
- {
- startTime = Time.time;
- }
- private void Update()
- {
- if (finnished)
- return;
- //timer settings
- float t = Time.time - startTime; //time gone since our timer starts
- string minutes = ((int)t / 60).ToString();
- string seconds = (t % 60).ToString("f0");
- timerText.text = minutes + ":" + seconds;
- }
- //Than our player finnishing
- public void Finnish()
- {
- finnished = true;
- //all text gets green
- timerText.color = Color.green;
- scoreText.color = Color.green;
- }
- }
Add Comment
Please, Sign In to add comment