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.
49 lines
1.2 KiB
C#
49 lines
1.2 KiB
C#
using System.Collections;
|
|
using Unity.Multiplayer.Samples.Utilities;
|
|
using Unity.Netcode;
|
|
using UnityEngine;
|
|
|
|
public class TimerScript : MonoBehaviour
|
|
{
|
|
[SerializeField] private SynchronizedTimer timer;
|
|
public ServerAdditiveSceneLoader serverAdditiveSceneLoader;
|
|
public int timeInSeconds = 180;
|
|
|
|
void Start()
|
|
{
|
|
if (timer != null)
|
|
{
|
|
timeInSeconds = 1200;
|
|
timer.OnTimerEnd += HandleTimerEnd;
|
|
Debug.Log("Timer started call sent");
|
|
StartCoroutine(Starter());
|
|
}
|
|
}
|
|
|
|
IEnumerator Starter()
|
|
{
|
|
yield return new WaitUntil(() => serverAdditiveSceneLoader.m_SceneState == ServerAdditiveSceneLoader.SceneState.Loaded);
|
|
if (NetworkManager.Singleton.IsServer)
|
|
{
|
|
yield return new WaitForSeconds(2.5f);
|
|
Debug.Log("Timer started call sent2");
|
|
|
|
timer.StartTimerServer(timeInSeconds);
|
|
}
|
|
}
|
|
|
|
private void HandleTimerEnd()
|
|
{
|
|
Debug.Log("Timer has ended!");
|
|
Scoreboard.instance.FinalLeaderBoard();
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
if (timer != null)
|
|
{
|
|
timer.OnTimerEnd -= HandleTimerEnd;
|
|
}
|
|
}
|
|
}
|