Upgraded ZDisabler with support of IsServer

This commit is contained in:
BOTAlex 2024-02-29 19:32:14 +01:00
parent a706cd7e45
commit 8b60e45bab
1 changed files with 14 additions and 1 deletions

View File

@ -5,13 +5,19 @@ using UnityEngine;
public class ZDisablerV2 : NetworkBehaviour
{
[Tooltip("Keep enabled if is [BLANK]")]
public KeepIf KeepEnabledIf = KeepIf.IsOwner;
[Tooltip("Add all the objects to disable on join, if not owner")]
public UnityEngine.Object[] objectsToDisable;
public override void OnNetworkSpawn()
{
// Run if networked
if (NetworkManager.Singleton == null || IsOwner) return;
if (NetworkManager.Singleton == null) return;
if (KeepEnabledIf == KeepIf.IsOwner && IsOwner) return;
if (KeepEnabledIf == KeepIf.IsServer && IsServer) return;
for (int i = 0; i < objectsToDisable.Length; i++)
{
@ -37,4 +43,11 @@ public class ZDisablerV2 : NetworkBehaviour
}
}
}
// Keep enabled if is [blank]
public enum KeepIf
{
IsServer,
IsOwner
}
}