SyncEvent
//Creates an instance of the event - True means that it is owner authority
[SerializeField] private SyncEvent<int> syncEvent = new(true);
protected override void OnSpawned()
{
//Listening to the event
syncEvent.AddListener(SyncEventTest);
}
private void SyncEventTest(int myValue)
{
//Everyone subscribed to the syncEvent will receive this value when the owner invokes it
Debug.Log($"Received value: {myValue} from SyncEvent");
}
public void InvokeSyncEvent()
{
//Because the event is owner auth, only the owner can call the event.
if (!isOwner)
return;
//Invoking the event as the owner with the value 10
syncEvent.Invoke(10);
}
Last updated