Я получаю эту ошибку:
«SetDestination» может быть вызван только для активного агента, который был помещен в NavMesh.UnityEngine.AI.NavMeshAgent: SetDestination (Vector3) EnemyController: Update () (в Assets / Scripts / EnemyController.cs: 30)
Мой вражеский контроллер выглядит так:
using UnityEngine;
using UnityEngine.AI;
[RequireComponent(typeof(NavMeshAgent))]
public class EnemyController : MonoBehaviour
{
public float lookRadius = 10f;
GameObject obj;
NavMeshAgent agent;
Transform target;
// Start is called before the first frame update
void Start()
{
obj = GameObject.FindGameObjectWithTag("Player");
target = obj.transform;
agent = GetComponent<NavMeshAgent>();
}
// Update is called once per frame
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);
}
}
I 'используя стандартный fpscontroller в качестве проигрывателя.
Есть ли способ заставить это работать?
С уважением.
/ Rudy