using System; using System.Collections; using System.Collections.Generic; using Unity.Netcode; using Unity.Netcode.Components; using UnityEngine; /// /// [Netcode for gameobjects] This is used for disabling components/objects depending on is host/server/client. /// public class ZNGODisabler : NetworkBehaviour { [SerializeField] private bool RunOnAwake = true; [Space(10)] [Tooltip("Add all the objects to disable on join")] public UnityEngine.Object[] objectsToDisable; private void Start() { if (RunOnAwake) ZDisable(); } public void ZDisable() { if (RunOnAwake && IsOwner) return; for (int i = 0; i < objectsToDisable.Length; i++) { var objectType = objectsToDisable[i]; // Apparently, "typeof" is not needed /shrug switch (objectType) { case MonoBehaviour monoBehaviour: monoBehaviour.enabled = false; break; case GameObject gameObject: gameObject.SetActive(false); break; case Rigidbody rigidbody: rigidbody.isKinematic = true; break; default: Debug.LogError($"Can't disable: {objectType.name} (not supported)", objectType); break; } } } }