Files
chameleon/Assets/Scripts/Network/SpectatorSetup.cs
T
adminandClaude Opus 4.8 e23fae0c50 Reorganize scripts into subfolders by responsibility
Move scripts under Assets/Scripts/ into Components, GameMode, Helper,
Network, Enum, Struct and ScriptableObject folders. Pure file moves
(plus folder .meta files); no code changes.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-02 15:02:15 +02:00

23 lines
978 B
C#

using Unity.Netcode;
using UnityEngine;
/// <summary>
/// Per-avatar glue for a mid-match SPECTATOR. The spectator object is deliberately empty - no body, no
/// renderer, no collider, no controller - because the free-fly camera is a separate, persistent scene
/// object (in Main) that drives its own rig off Camera.main and needs nothing from this avatar. So the
/// spectator only has to exist as the owner's player object and flip the local mode set to free-cam-only.
/// The owner does that here; remote peers do nothing (there is no body to show or simulate). When the
/// host ends the match, MatchManager respawns this client as a neutral lobby Player.
/// </summary>
[DisallowMultipleComponent]
public class SpectatorSetup : NetworkBehaviour
{
public override void OnNetworkSpawn()
{
if (!IsOwner) return;
var manager = FindFirstObjectByType<GameModeManager>(FindObjectsInactive.Include);
if (manager) manager.BindSpectator();
}
}