using Unity.Netcode;
using UnityEngine;
///
/// Sits on the Lobby's "Start Match" trigger volume (a BoxCollider with isTrigger on). When the HOST's
/// own player walks in, it asks the to start the match. Server-gated: pure
/// clients fire nothing (IsServer is false there), and only the host-owned player object counts, so a
/// remote avatar passing through never starts the match. The trigger lives in the additively-loaded
/// Lobby and is destroyed when the lobby unloads, so it cannot start a second match.
///
[RequireComponent(typeof(Collider))]
[DisallowMultipleComponent]
public class StartMatchTrigger : MonoBehaviour
{
private void OnTriggerEnter(Collider other)
{
var nm = NetworkManager.Singleton;
if (!nm || !nm.IsServer) return; // only the server/host starts the match
var netObj = other.GetComponentInParent();
if (!netObj || !netObj.IsPlayerObject) return; // must be a player avatar
if (netObj.OwnerClientId != nm.LocalClientId) return; // ...and specifically the host's own
if (MatchManager.Instance) MatchManager.Instance.StartMatch();
}
}