Quantcast
Channel: Answers for "Count down timer C#"
Viewing all articles
Browse latest Browse all 22

Answer by Maltory

$
0
0
So this is the super basic timer I am currently working on. I am using it for a world space UI so.... But hopefully it works for all of you guys. using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class CountDownTimer : MonoBehaviour { public Text timerText; [SerializeField] private float timeLimit = 10f; private bool activeTimer = true; private float t; GameObject player;//reference to the player gameobject (not sure if needed) PlayerHealth playerHealth;// reference to the health script private void Awake() { player = GameObject.FindGameObjectWithTag("Player"); playerHealth = player.GetComponent(); } // Update is called once per frame void Update() { if (!activeTimer) return; t = timeLimit - Time.time; string minutes = ((int)t / 60).ToString(); string seconds = (t % 60).ToString("f2"); timerText.text = minutes + ":" + seconds; if (t <= 0) { TimeRanOut(); }

Viewing all articles
Browse latest Browse all 22

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>