1

我尝试了所有方法,我手动烘焙了导航网格,但仍然无法正常工作。如果您知道如何解决该问题,请帮助我。

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

public class EnemyController : MonoBehaviour {

    public float lookRadius = 10f;
    Transform target;
    public NavMeshAgent agent;

    void Start () {
        target = PlayerManager.instance.player.transform;
        agent = GetComponent<NavMeshAgent> ();
        if (agent.isOnNavMesh == false)
            Debug.Log ("NOOOOOO");
    }

    void Update () {
        float distance = Vector3.Distance (target.position, transform.position);
        if (distance <= lookRadius){
            agent.SetDestination (target.position);
        }
    }

    void OnDrawGizmosSelected() {
        Gizmos.color = Color.red;
        Gizmos.DrawWireSphere(transform.position, lookRadius);
    }
}
4

0 回答 0