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.
102 lines
2.4 KiB
C#
102 lines
2.4 KiB
C#
using UnityEngine;
|
|
using TMPro;
|
|
using System.Collections;
|
|
|
|
public class RaceCountdownManager : MonoBehaviour
|
|
{
|
|
public static RaceCountdownManager Instance;
|
|
|
|
[SerializeField] private TextMeshProUGUI countdownText;
|
|
private int countdownTimer;
|
|
public bool RaceStarted { get; private set; }
|
|
|
|
private void Awake()
|
|
{
|
|
Instance = this;
|
|
if (countdownText != null)
|
|
countdownText.gameObject.SetActive(false);
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
StartCoroutine(CountdownCoroutine());
|
|
}
|
|
|
|
private IEnumerator CountdownCoroutine()
|
|
{
|
|
countdownTimer = 3;
|
|
countdownText.gameObject.SetActive(true);
|
|
|
|
while (countdownTimer > 0)
|
|
{
|
|
countdownText.text = countdownTimer.ToString();
|
|
yield return new WaitForSeconds(1f);
|
|
countdownTimer--;
|
|
}
|
|
|
|
countdownText.gameObject.SetActive(false);
|
|
RaceStarted = true;
|
|
}
|
|
}
|
|
|
|
|
|
//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);
|
|
// }
|
|
// }
|
|
//}
|