본문 바로가기
개발/C#

유니티 C# 플레이어를 추적하는 적 코드 간단 구현 Unity

by SPNK 2023. 3. 19.
반응형
  • 코드 작성
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;
    }
}
반응형

댓글