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

41 lines
1.2 KiB
C#

3 weeks ago
using System.Collections;
using Unity.Multiplayer.Samples.Utilities;
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
}
private void OnDestroy()
{
if (timer != null)
{
timer.OnTimerEnd -= HandleTimerEnd; // Unsubscribe to avoid memory leaks
}
}
}