블랙잭 이동 및 애니메이션 수정

This commit is contained in:
dldydtn9755-crypto
2026-06-16 16:46:52 +09:00
parent acc3802bc5
commit 980576f1e5
7 changed files with 1101 additions and 11 deletions

View File

@@ -1,3 +1,4 @@
using System.Collections;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.InputSystem;
@@ -18,13 +19,19 @@ public class HookWalkToTable : MonoBehaviour
public Animator animator;
public string walkBoolName = "isWalking";
public string sitTriggerName = "sitTrigger";
public string standTriggerName = "standTrigger";
[Header("Stand Up Setting")]
public float standUpDuration = 1.5f;
[Header("Collision")]
public bool disableCollidersWhenSitting = true;
public bool enableCollidersAfterStandUp = true;
public Collider[] hookColliders;
[Header("Test")]
public Key testStartKey = Key.T;
public Key testStandUpKey = Key.Y;
private NavMeshAgent agent;
@@ -32,6 +39,7 @@ public class HookWalkToTable : MonoBehaviour
private bool isMoving = false;
private bool hasArrived = false;
private bool isSitting = false;
private bool isStandingUp = false;
private Vector3 currentDestination;
@@ -50,9 +58,10 @@ void Start()
if (animator != null)
{
animator.SetBool(walkBoolName, false);
animator.ResetTrigger(sitTriggerName);
animator.ResetTrigger(standTriggerName);
}
// Inspector에 Collider를 안 넣어도 자동으로 후크 자식 콜라이더들을 찾아줌
if (hookColliders == null || hookColliders.Length == 0)
{
hookColliders = GetComponentsInChildren<Collider>();
@@ -61,12 +70,18 @@ void Start()
void Update()
{
// 테스트용: T 누르면 출발
// 테스트용: T 누르면 테이블로 이동 후 앉기
if (Keyboard.current != null && Keyboard.current[testStartKey].wasPressedThisFrame)
{
StartWalking();
}
// 테스트용: Y 누르면 일어나기
if (Keyboard.current != null && Keyboard.current[testStandUpKey].wasPressedThisFrame)
{
StandUp();
}
if (!isMoving || agent == null)
{
return;
@@ -99,7 +114,7 @@ public void StartWalking()
return;
}
if (isMoving || hasArrived || isSitting)
if (isMoving || isSitting || isStandingUp)
{
return;
}
@@ -108,8 +123,12 @@ public void StartWalking()
hasArrived = false;
isMoving = true;
EnableHookColliders();
if (animator != null)
{
animator.ResetTrigger(sitTriggerName);
animator.ResetTrigger(standTriggerName);
animator.SetBool(walkBoolName, true);
}
@@ -159,8 +178,9 @@ void ArriveAndSit()
isMoving = false;
hasArrived = true;
isSitting = true;
isStandingUp = false;
// 1. NavMeshAgent 먼저 끄기
// 1. 이동 중지
if (agent != null)
{
agent.isStopped = true;
@@ -168,8 +188,7 @@ void ArriveAndSit()
agent.enabled = false;
}
// 2. 후크 몸 Collider 끄기
// 의자/테이블 콜라이더에 밀려서 위로 올라가는 문제 방지
// 2. 앉아 있는 동안 후크 콜라이더 끄기
if (disableCollidersWhenSitting)
{
DisableHookColliders();
@@ -190,12 +209,59 @@ void ArriveAndSit()
if (animator != null)
{
animator.SetBool(walkBoolName, false);
animator.ResetTrigger(standTriggerName);
animator.ResetTrigger(sitTriggerName);
animator.SetTrigger(sitTriggerName);
}
Debug.Log("Hook moved to sit point and started sitting.");
}
public void StandUp()
{
if (!isSitting || isStandingUp)
{
return;
}
StartCoroutine(StandUpRoutine());
}
IEnumerator StandUpRoutine()
{
isStandingUp = true;
isSitting = false;
if (animator != null)
{
animator.SetBool(walkBoolName, false);
animator.ResetTrigger(sitTriggerName);
animator.ResetTrigger(standTriggerName);
animator.SetTrigger(standTriggerName);
}
Debug.Log("Hook started stand up animation.");
yield return new WaitForSeconds(standUpDuration);
if (enableCollidersAfterStandUp)
{
EnableHookColliders();
}
if (agent != null)
{
agent.enabled = true;
agent.isStopped = true;
agent.ResetPath();
}
hasArrived = false;
isStandingUp = false;
Debug.Log("Hook stood up.");
}
void DisableHookColliders()
{
if (hookColliders == null || hookColliders.Length == 0)
@@ -212,6 +278,22 @@ void DisableHookColliders()
}
}
void EnableHookColliders()
{
if (hookColliders == null || hookColliders.Length == 0)
{
return;
}
foreach (Collider col in hookColliders)
{
if (col != null)
{
col.enabled = true;
}
}
}
void StopWalking()
{
isMoving = false;