1,利用navigation内置的运动控制
2,自己控制运动
3,运行时构建导航网格
重要组件
NavMesh Agent(导航网格代理 挂载在怪物上)
off-Mesh Link (网格链接)
NavMesh Obstacle(障碍,不经常移动勾选Carve)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class controlPlayer : MonoBehaviour {
private NavMeshAgent nav;
public float rotateSmoothing = 7; //转向速度
public float speed = 5;
// Use this for initialization
void Start () {
nav = this.GetComponent<NavMeshAgent>();
nav.updatePosition = false; //禁用导航控制的运动和转向
nav.updateRotation = false;
}
// Update is called once per frame
void Update () {
if (Input.GetMouseButton(0))
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;