You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
1.3 KiB
C#
60 lines
1.3 KiB
C#
using UnityEngine;
|
|
using TMPro;
|
|
using Fusion;
|
|
using System.Collections;
|
|
|
|
public class RaceCountdownManager : NetworkBehaviour
|
|
{
|
|
public static RaceCountdownManager Instance;
|
|
|
|
[SerializeField] private TextMeshProUGUI countdownText;
|
|
|
|
[Networked, OnChangedRender(nameof(OnCountdownChanged))]
|
|
private int CountdownTimer { get; set; }
|
|
|
|
[Networked] public bool RaceStarted { get; private set; }
|
|
|
|
private void Awake()
|
|
{
|
|
Instance = this;
|
|
if (countdownText != null)
|
|
countdownText.gameObject.SetActive(false);
|
|
}
|
|
|
|
public override void Spawned()
|
|
{
|
|
if (Object.HasStateAuthority)
|
|
{
|
|
StartCoroutine(CountdownCoroutine());
|
|
}
|
|
}
|
|
|
|
private IEnumerator CountdownCoroutine()
|
|
{
|
|
CountdownTimer = 3;
|
|
countdownText.gameObject.SetActive(true);
|
|
|
|
while (CountdownTimer > 0)
|
|
{
|
|
yield return new WaitForSeconds(1f);
|
|
CountdownTimer--;
|
|
}
|
|
|
|
RaceStarted = true;
|
|
countdownText.gameObject.SetActive(false);
|
|
}
|
|
|
|
private void OnCountdownChanged()
|
|
{
|
|
if (CountdownTimer > 0)
|
|
{
|
|
countdownText.text = CountdownTimer.ToString();
|
|
countdownText.gameObject.SetActive(true);
|
|
}
|
|
else
|
|
{
|
|
countdownText.gameObject.SetActive(false);
|
|
}
|
|
}
|
|
}
|