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/Gameplay/ClientReadyHelper.cs

37 lines
816 B
C#

using System;
using System.Collections;
using Unity.Netcode;
using UnityEngine;
public class ClientReadyHelper : MonoBehaviour
{
private static bool isClientReady = false;
public static void SetClientReady()
{
isClientReady = true;
Debug.Log("[Client] Client is now ready to receive RPCs.");
}
public static bool IsClientReady()
{
return isClientReady;
}
public static void ProcessRPC(Action action, MonoBehaviour caller)
{
if (!isClientReady)
{
caller.StartCoroutine(WaitForClientReady(action));
return;
}
action.Invoke();
}
private static IEnumerator WaitForClientReady(Action action)
{
yield return new WaitUntil(() => isClientReady);
action.Invoke();
}
}