#looking for help converting a regular text to text mesh pro

1 messages · Page 1 of 1 (latest)

lapis dock
#
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();
    }
}```
wanton moss
#

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

potent crane
#

And don't use InvokeRepeating

#

Just do the stuff in Update

wanton moss
#

Or coroutine atleast