Unity 엔진을 활용한 적 오브젝트 AI를 적용한 따라가기 연구

neulilanikka·2022년 11월 26일
0

프로젝트(Project)

목록 보기
27/27


1. Project 탭에 우클릭 후, C# Script를 생성합니다.


2. 생성된 파일의 이름을 AIMOVE로 변경합니다.

using System.Collections;
using System.Collections.Generic; using UnityEngine;
using UnityEngine.AI;

public class AIMOVE : MonoBehaviour{ 
       public GameObject Player;
       public NavMeshAgent agent;// Start is called before the first frame update

       void Start(){
          agent = GetComponent<NavMeshAgent>();
       }// Update is called once per frame

       void Update(){
          agent.SetDestination(Player.transform.position); 
       }
}
   
  1. C# 파일을 더블클릭 후, 다음 코드를 입력하고 저장합니다.


4. 적 오브젝트에 C# 파일을 드래그 드롭하고 적 오브젝트 선택 후, Inspector 탭을 확인합니다.


5. Player 부분에 무기 에셋을 드래그 드롭합니다.


6. 그 밑에 Add Component를 선택한 후 Nav Mesh Agent를 선택합니다.


7. 다음과 같이 스피드를 수정해줍니다.


8. Window에서 AI > Navigation을 선택합니다.


9. 다음과 같은 창이 뜨게 됩니다.


10. Terrians를 선택합니다.


11. Bake로 들어가서 아래의 Bake 버튼을 선택합니다.


12. 상단 중앙의 버튼 중 Play 버튼(게임 시작)을 눌러줍니다.


13. 게임 플레이 중 적이 플레이어를 따라오는 것을 확인할 수 있습니다.

profile
Now: Mobile Developer

0개의 댓글

관련 채용 정보