using Unity.BossRoom.Gameplay.GameplayObjects.Character; using UnityEngine; namespace Unity.Multiplayer.Samples.BossRoom { [RequireComponent(typeof(Collider))] public class Platform : MonoBehaviour { public int PlatformID { get; private set; } 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. } } /// /// Sets the unique ID for the platform. /// /// The unique ID to assign. public void AssignID(int id) { PlatformID = id; Debug.Log($"Platform {name} assigned ID: {PlatformID}"); } /// /// 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}."); } } } }