SyncTimer
public TMP_Text timerText;
//false = OwnerAuth
//3 = Reoncile interval
//The reconcile interval deciphers how often it will force align all clients
private SyncTimer timer = new();
private void Awake()
{
//onTimerSecondTick is called every 1 second
timer.onTimerSecondTick += OnTimerSecondTick;
}
protected override void OnSpawned(bool asServer)
{
//This starts the timer with 30 seconds countdown
if(isOwner)
timer.StartTimer(30f);
}
private void OnTimerSecondTick()
{
//You can also get .remaining to get the precise float value
//For displaying timers, the remainingInt makes it easy
timerText.text = timer.remainingInt.ToString();
}
private void PauseGameTimer()
{
//Pauses the timer and will sync the remaining time because it's set to true
timer.PauseTimer(true);
}
private void ResumeGameTimer()
{
//Will resume the timer from where it was paused
timer.ResumeTimer();
}Last updated