반응형
- 코드 작성
using UnityEngine;
public class Enemy : MonoBehaviour
{
public float speed = 5f;
private Transform player;
void Start()
{
// 태그로 플레이어 찾기
player = GameObject.FindGameObjectWithTag("Player").transform;
}
void Update()
{
Vector3 direction = player.position - transform.position;
direction.Normalize();
transform.position += direction * speed * Time.deltaTime;
}
}
반응형