헤엄치는 고래별, 움직이는 해산물
This commit is contained in:
51
Assets/02_Scripts/MazeRoom/SeaCreatureWaypoint.cs
Normal file
51
Assets/02_Scripts/MazeRoom/SeaCreatureWaypoint.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class SeaCreatureWaypoint : MonoBehaviour
|
||||
{
|
||||
[Header("Waypoint Settings")]
|
||||
public Transform[] waypoints;
|
||||
|
||||
[Header("Movement Settings")]
|
||||
public float moveSpeed = 2f;
|
||||
public float rotationSpeed = 5f;
|
||||
public float arriveDistance = 0.2f;
|
||||
|
||||
private int currentWaypoint = 0;
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (waypoints == null || waypoints.Length == 0)
|
||||
return;
|
||||
|
||||
Transform target = waypoints[currentWaypoint];
|
||||
|
||||
// 이동
|
||||
transform.position = Vector3.MoveTowards(
|
||||
transform.position,
|
||||
target.position,
|
||||
moveSpeed * Time.deltaTime);
|
||||
|
||||
// 바라보는 방향
|
||||
Vector3 direction = target.position - transform.position;
|
||||
|
||||
if (direction != Vector3.zero)
|
||||
{
|
||||
Quaternion targetRotation = Quaternion.LookRotation(direction);
|
||||
transform.rotation = Quaternion.Slerp(
|
||||
transform.rotation,
|
||||
targetRotation,
|
||||
rotationSpeed * Time.deltaTime);
|
||||
}
|
||||
|
||||
// 도착하면 다음 웨이포인트
|
||||
if (Vector3.Distance(transform.position, target.position) < arriveDistance)
|
||||
{
|
||||
currentWaypoint++;
|
||||
|
||||
if (currentWaypoint >= waypoints.Length)
|
||||
{
|
||||
currentWaypoint = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/02_Scripts/MazeRoom/SeaCreatureWaypoint.cs.meta
Normal file
2
Assets/02_Scripts/MazeRoom/SeaCreatureWaypoint.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fb034270e545f1f42be49ca0557e2c46
|
||||
Reference in New Issue
Block a user