41 lines
1.2 KiB
C#
41 lines
1.2 KiB
C#
using UnityEngine;
|
|
|
|
namespace Unheimlich.World.Environment
|
|
{
|
|
/// <summary>
|
|
/// Placed on the trigger child of an <see cref="InfiniteStaircaseController"/>.
|
|
/// Forwards Player trigger enter / exit events to the parent controller.
|
|
/// </summary>
|
|
[RequireComponent(typeof(Collider))]
|
|
public class StaircaseTriggerZone : MonoBehaviour
|
|
{
|
|
private const string PlayerTag = "Player";
|
|
|
|
private InfiniteStaircaseController _controller;
|
|
|
|
private void Awake()
|
|
{
|
|
_controller = GetComponentInParent<InfiniteStaircaseController>();
|
|
|
|
if (_controller == null)
|
|
Debug.LogWarning($"[StaircaseTriggerZone] No InfiniteStaircaseController found in parent of '{name}'.", this);
|
|
}
|
|
|
|
private void OnTriggerEnter(Collider other)
|
|
{
|
|
if (_controller == null) return;
|
|
if (!other.CompareTag(PlayerTag)) return;
|
|
|
|
_controller.OnPlayerEnteredTrigger();
|
|
}
|
|
|
|
private void OnTriggerExit(Collider other)
|
|
{
|
|
if (_controller == null) return;
|
|
if (!other.CompareTag(PlayerTag)) return;
|
|
|
|
_controller.OnPlayerExitedTrigger();
|
|
}
|
|
}
|
|
}
|