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.
HighGroundRoyaleNetcode/Assets/Scripts/TimerScript.cs

49 lines
1.2 KiB
C#

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