using System.Collections; using Unity.Multiplayer.Samples.Utilities; using Unity.Netcode; using UnityEngine; using static TMPro.SpriteAssetUtilities.TexturePacker_JsonArray; public class TimerScript : MonoBehaviour { [SerializeField] private SynchronizedTimer timer; public ServerAdditiveSceneLoader serverAdditiveSceneLoader; public int timeInSeconds=180; void Start() { if (timer != null) { timer.OnTimerEnd += HandleTimerEnd; // Subscribe to the event StartCoroutine(Starter()); } } IEnumerator Starter() { yield return new WaitUntil(() => serverAdditiveSceneLoader.m_SceneState == ServerAdditiveSceneLoader.SceneState.Loaded); if (Unity.Netcode.NetworkManager.Singleton.IsServer) { timer.StartTimerServerRpc(timeInSeconds); // Start a 3-minute timer } } private void HandleTimerEnd() { Debug.Log("Timer has ended!"); // Add logic for what happens when the timer ends Scoreboard.instance.FinalLeaderBoard(); } private void OnDestroy() { if (timer != null) { timer.OnTimerEnd -= HandleTimerEnd; // Unsubscribe to avoid memory leaks } } }