using Unity.BossRoom.Gameplay.GameplayObjects.Character; using UnityEngine; namespace Unity.Multiplayer.Samples.BossRoom { [RequireComponent(typeof(Collider))] public class Platform : MonoBehaviour { public bool IsOccupied => Occupier != null; public ServerCharacter Occupier { get; private set; } private Collider m_PlatformCollider; private void Awake() { m_PlatformCollider = GetComponent(); if (!m_PlatformCollider.isTrigger) { Debug.LogWarning($"Platform {name} collider must be set as a trigger."); m_PlatformCollider.isTrigger = true; // Ensure it's a trigger. } } /// /// Marks this platform as occupied by a specific player. /// /// The ServerCharacter occupying the platform. public void Occupy(ServerCharacter player) { if (IsOccupied) { Debug.LogWarning($"Platform {name} is already occupied by {Occupier.name}."); return; } Occupier = player; Debug.Log($"{player.name} has occupied Platform {name}."); } /// /// Clears the occupation of this platform. /// public void Vacate() { if (!IsOccupied) { Debug.LogWarning($"Platform {name} is not currently occupied."); return; } Debug.Log($"{Occupier.name} has vacated Platform {name}."); Occupier = null; } private void OnTriggerEnter(Collider other) { if (!IsOccupied && other.TryGetComponent(out var player)) { Occupy(player); Debug.Log($"{player.name} has entered Platform {name}."); } } private void OnTriggerExit(Collider other) { if (IsOccupied && other.TryGetComponent(out var player) && player == Occupier) { Vacate(); Debug.Log($"{player.name} has exited Platform {name}."); } } } }