using UnityEngine.UI;
using System.Linq;
using System;
using TMPro;
public class Timer : MonoBehaviour {
private int TimeLeft;
// [SerializeField]
private Text textBlock;
void Start ()
{
textBlock = FindObjectsOfType<Text>().Where(x => x.name == "TimeLeft").FirstOrDefault();
TimeLeft = 400;
InvokeRepeating("UpdateTime", 0, 0.33f);
}
void UpdateTime ()
{
if (textBlock)
textBlock.text = (TimeLeft--).ToString();
}
}```
#looking for help converting a regular text to text mesh pro
1 messages · Page 1 of 1 (latest)
That code is neither good way to handle references nor update something every frame, anyways, instead of Text, you should make a variable of type TextMeshProUGUI
And the biggest problem in that code is that its not framerate independent, at higher framerates, TimeLeft will obviously decrease faster, you should use Time.deltaTime to decrease the timer
Or coroutine atleast