Unity

유니티 내비게이션 navigation

모카쨩 2020. 10. 25. 14:18

 

 

스탠다드 에셋 방식

더보기

먼저 스탠다드 에셋을 다운받는다

 

 

unityStandardAssetNavAI.unitypackage
8.83MB

 

 

3D모델의 애니메이터가 있는 최상단에 ThirdPersonAnimatorController를 넣는다

 

AI캐릭터 컨트롤을 넣고 이동하고자 하는 지점의 트랜스폼을 넣는다

 

Third Person Character의 Ground Check Distance값을 0.2로 수정한다.

왜냐하면 기본값은 Ground Check Distance가 너무 작아서 지면판정이 안되기 때문이다

 

Window-> AI/Navigation을 누른다

 

베이크 하면 완료된다

 

커스텀 방식

더보기

 

 

AIControl 코드

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

public class AIControl : MonoBehaviour
{

    public Transform target;
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        var agent = GetComponent<NavMeshAgent>();
        if ((target != null)&& (agent != null))
        {
            agent.SetDestination(target.position);
        }
    }
}

 

저렇게 배치하고 AIControl을 넣는다