33 lines
962 B
C#
33 lines
962 B
C#
using UnityEngine;
|
|
|
|
public class EnemyShip : MonoBehaviour
|
|
{
|
|
[Header("Target Settings")]
|
|
// 따라갈 대상(플레이어)를 할당
|
|
public Transform player;
|
|
|
|
[Header("Movement Settings")]
|
|
public float moveSpeed = 5f;
|
|
public float rotationSpeed = 10f;
|
|
|
|
public float fixedY = 0f;
|
|
|
|
private void Update()
|
|
{
|
|
if (player == null)
|
|
return;
|
|
|
|
Vector3 targetPos = new Vector3(player.position.x, fixedY, player.position.z);
|
|
transform.position = Vector3.MoveTowards(transform.position, targetPos, moveSpeed * Time.deltaTime);
|
|
|
|
Vector3 direction = (player.position - transform.position).normalized;
|
|
direction.y = 0f;
|
|
|
|
if (direction != Vector3.zero)
|
|
{
|
|
Quaternion targetRotation = Quaternion.LookRotation(direction);
|
|
transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, rotationSpeed * Time.deltaTime);
|
|
}
|
|
}
|
|
}
|