Basics

確認済のバージョン: 2017.3

-

難易度: 初級

Learn how to create AI pathfinding using the Unity NavMesh components! This video was produced by Brackeys.

Basics

初級 Navigation

Download the Example Project here.

PlayerController

Code snippet

using UnityEngine;
using UnityEngine.AI;

public class PlayerController : MonoBehaviour {

    public Camera cam;

    public NavMeshAgent agent;
    
    // Update is called once per frame
    void Update () 
    {
        if (Input.GetMouseButtonDown(0))
        {
            Ray ray = cam.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;

            if (Physics.Raycast(ray, out hit))
            {
                agent.SetDestination(hit.point);
            }
        }
    }
}

関連するチュートリアル