컴퓨터 설정까지
This commit is contained in:
104
Assets/02_Scripts/Story/ch4 scrip/JunpyoRunToPoint.cs
Normal file
104
Assets/02_Scripts/Story/ch4 scrip/JunpyoRunToPoint.cs
Normal file
@@ -0,0 +1,104 @@
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
|
||||
public class JunpyoRunToPoint : MonoBehaviour
|
||||
{
|
||||
[Header("Junpyo")]
|
||||
[SerializeField] private Transform junpyo;
|
||||
|
||||
[Header("Target")]
|
||||
[SerializeField] private Transform junpyoStopPoint;
|
||||
|
||||
[Header("Movement")]
|
||||
[SerializeField] private float moveDuration = 1.2f;
|
||||
[SerializeField] private bool faceMoveDirection = true;
|
||||
|
||||
private bool isMoving;
|
||||
private bool hasMoved;
|
||||
|
||||
// 대화가 시작될 때 호출
|
||||
public void RunToStopPoint()
|
||||
{
|
||||
if (isMoving || hasMoved)
|
||||
return;
|
||||
|
||||
if (junpyo == null || junpyoStopPoint == null)
|
||||
{
|
||||
Debug.LogWarning("구준표 또는 JunpyoStopPoint가 연결되지 않았습니다.");
|
||||
return;
|
||||
}
|
||||
|
||||
hasMoved = true;
|
||||
StartCoroutine(MoveRoutine());
|
||||
}
|
||||
|
||||
private IEnumerator MoveRoutine()
|
||||
{
|
||||
isMoving = true;
|
||||
|
||||
Vector3 startPosition = junpyo.position;
|
||||
Quaternion startRotation = junpyo.rotation;
|
||||
|
||||
Vector3 targetPosition = junpyoStopPoint.position;
|
||||
targetPosition.y = startPosition.y;
|
||||
|
||||
Vector3 direction = targetPosition - startPosition;
|
||||
direction.y = 0f;
|
||||
|
||||
Quaternion targetRotation = startRotation;
|
||||
|
||||
if (faceMoveDirection && direction.sqrMagnitude > 0.001f)
|
||||
targetRotation = Quaternion.LookRotation(direction.normalized);
|
||||
|
||||
float elapsed = 0f;
|
||||
|
||||
while (elapsed < moveDuration)
|
||||
{
|
||||
elapsed += Time.deltaTime;
|
||||
float t = Mathf.Clamp01(elapsed / moveDuration);
|
||||
|
||||
junpyo.position = Vector3.Lerp(
|
||||
startPosition,
|
||||
targetPosition,
|
||||
t
|
||||
);
|
||||
|
||||
if (faceMoveDirection)
|
||||
{
|
||||
junpyo.rotation = Quaternion.Slerp(
|
||||
startRotation,
|
||||
targetRotation,
|
||||
t
|
||||
);
|
||||
}
|
||||
|
||||
yield return null;
|
||||
}
|
||||
|
||||
// 마지막 위치를 정확하게 맞춤
|
||||
junpyo.position = targetPosition;
|
||||
|
||||
if (faceMoveDirection)
|
||||
junpyo.rotation = targetRotation;
|
||||
|
||||
isMoving = false;
|
||||
}
|
||||
|
||||
public void ResetMovement()
|
||||
{
|
||||
hasMoved = false;
|
||||
isMoving = false;
|
||||
}
|
||||
|
||||
[ContextMenu("Test Run")]
|
||||
private void TestRun()
|
||||
{
|
||||
RunToStopPoint();
|
||||
}
|
||||
|
||||
[ContextMenu("Reset Run")]
|
||||
private void TestResetRun()
|
||||
{
|
||||
ResetMovement();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user