Cleaned up and commented version.

This commit is contained in:
Thorbjoern
2025-10-02 00:07:11 +02:00
parent 2b86d9f0a2
commit 4c613c3436
66 changed files with 260 additions and 1020 deletions
@@ -0,0 +1,47 @@
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";
}
}
}