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#
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;
|
||
1 week ago
|
public int timeInSeconds = 180;
|
||
|
|
||
1 month ago
|
void Start()
|
||
|
{
|
||
|
if (timer != null)
|
||
|
{
|
||
1 week ago
|
timeInSeconds = 1200;
|
||
|
timer.OnTimerEnd += HandleTimerEnd;
|
||
|
Debug.Log("Timer started call sent");
|
||
1 month ago
|
StartCoroutine(Starter());
|
||
|
}
|
||
|
}
|
||
1 week ago
|
|
||
1 month ago
|
IEnumerator Starter()
|
||
|
{
|
||
|
yield return new WaitUntil(() => serverAdditiveSceneLoader.m_SceneState == ServerAdditiveSceneLoader.SceneState.Loaded);
|
||
1 week ago
|
if (NetworkManager.Singleton.IsServer)
|
||
1 month ago
|
{
|
||
1 week ago
|
yield return new WaitForSeconds(2.5f);
|
||
|
Debug.Log("Timer started call sent2");
|
||
|
|
||
|
timer.StartTimerServer(timeInSeconds);
|
||
1 month ago
|
}
|
||
|
}
|
||
1 week ago
|
|
||
1 month ago
|
private void HandleTimerEnd()
|
||
|
{
|
||
|
Debug.Log("Timer has ended!");
|
||
4 weeks ago
|
Scoreboard.instance.FinalLeaderBoard();
|
||
1 month ago
|
}
|
||
1 week ago
|
|
||
1 month ago
|
private void OnDestroy()
|
||
|
{
|
||
|
if (timer != null)
|
||
|
{
|
||
1 week ago
|
timer.OnTimerEnd -= HandleTimerEnd;
|
||
1 month ago
|
}
|
||
|
}
|
||
|
}
|