fgm24/Assets/Scripts/Multiplayer/ZDisablerV2.cs

41 lines
1.1 KiB
C#

using System.Collections;
using System.Collections.Generic;
using Unity.Netcode;
using UnityEngine;
public class ZDisablerV2 : NetworkBehaviour
{
[Tooltip("Add all the objects to disable on join, if not owner")]
public UnityEngine.Object[] objectsToDisable;
private void OnEnable()
{
// Run if networked
if (NetworkManager.Singleton == null || 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;
}
}
}
}