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);
            }
        }
    }
}

Связанные обучающие материалы