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

Answer by Nomabond

$
0
0
Hi Nocturnal, On line 13 you are using GetComponent(); but the actual component you are trying to find is a Text (notice the capital 'T' ). It would be much easier for you though if you set your Text text to a public variable and then use the inspector to drag the reference of your UI Text into the script. Here is a slightly modified version of your script that you can use to get a nice rounded integer countdown from 300. Let me know if you have any questions about it! using UnityEngine; using UnityEngine.UI; using System.Collections; public class CountDown : MonoBehaviour { float timeLeft = 300.0f; public Text text; void Update() { timeLeft -= Time.deltaTime; text.text = "Time Left:" + Mathf.Round(timeLeft); if(timeLeft < 0) { Application.LoadLevel("gameOver"); } } }

Viewing all articles
Browse latest Browse all 22

Trending Articles



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