using Unity.Netcode;
using UnityEngine;

public class LocalOnly : NetworkBehaviour
{
    public Behaviour[] componentsToDisable;
    public GameObject[] objectsToDisable;
    public GameObject[] objectsToTag;

    public override void OnNetworkSpawn()
    {
        if (!IsOwner)
        {

            foreach (var comp in componentsToDisable)
            {
                if (comp != null) comp.enabled = false;
            }

            foreach (var obj in objectsToDisable)
            {
                if (obj != null) obj.SetActive(false);
            }

            foreach(var obj in objectsToTag)
            {
                if (obj != null)
                {
                    obj.tag = "RemotePlayer";
                    obj.layer = 0;
                }
            }

            // Kamera-Tags sicherstellen
            Camera cam = GetComponentInChildren<Camera>();
            if (cam != null && cam.CompareTag("MainCamera"))
                cam.enabled = false;
        }
        else
        {
            // Nur der lokale Spieler darf "MainCamera" haben
            Camera cam = GetComponentInChildren<Camera>();
            if (cam != null)
                cam.tag = "MainCamera";
        }
    }
}
