게임클리어 이벤트

This commit is contained in:
2026-06-23 17:03:38 +09:00
parent fecc7556d6
commit b85855d4d6
25 changed files with 1317 additions and 28 deletions

View File

@@ -3,9 +3,13 @@
// 대상(보통 플레이어)을 NavMesh 위에서 따라다니는 간단한 동행 스크립트.
// 속도/가속/높이(Base Offset) 등은 NavMeshAgent 컴포넌트에서 설정한다.
// 추적은 _followEnabled로 동적으로 켜고/끌 수 있다.
[RequireComponent(typeof(NavMeshAgent))]
public class FollowObject : MonoBehaviour
{
[Header("Enable")]
[SerializeField] private bool _followEnabled = true; // 추적 on/off (런타임에 동적 변경 가능)
[Header("Target")]
[SerializeField] private Transform _target; // 비워두면 Camera.main 사용
@@ -20,14 +24,23 @@ public class FollowObject : MonoBehaviour
private NavMeshAgent _agent;
private float _repathTimer;
public bool FollowEnabled
{
get => _followEnabled;
set => SetFollowEnabled(value);
}
private void Awake()
{
_agent = GetComponent<NavMeshAgent>();
_agent.stoppingDistance = _followDistance;
ApplyAgentStopped();
}
private void Update()
{
if (!_followEnabled) return;
var target = ResolveTarget();
if (target == null || !_agent.isOnNavMesh) return;
@@ -45,6 +58,28 @@ private void Update()
FaceTarget(target);
}
// ── 동적 on/off ──────────────────────────────────────────────
public void SetFollowEnabled(bool on)
{
_followEnabled = on;
if (on) _repathTimer = 0f; // 켜면 즉시 경로 재계산
ApplyAgentStopped();
}
public void EnableFollow() => SetFollowEnabled(true); // UnityEvent 연결용(무인자)
public void DisableFollow() => SetFollowEnabled(false);
// 끄면 즉시 멈추고 남은 경로 제거(잔여 이동 방지), 켜면 이동 재개
private void ApplyAgentStopped()
{
if (_agent == null || !_agent.isActiveAndEnabled || !_agent.isOnNavMesh) return;
_agent.isStopped = !_followEnabled;
if (!_followEnabled)
_agent.ResetPath();
}
// ─────────────────────────────────────────────────────────────
private void FaceTarget(Transform target)
{
Vector3 dir = target.position - transform.position;