I used the script that was in documentation to understand NPC movement, but it not working it keep on saying
- “SetDestination” can only be called on an active agent that has been placed on a NavMesh.UnityEngine.AI.NavMeshAgent:set_destination(Vector3)
- “GetRemainingDistance” can only be called on an active agent that has been placed on a NavMesh.
UnityEngine.AI.NavMeshAgent:get_remainingDistance()
I dont know what to do.
here is the script:
using UnityEngine;
using UnityEngine.AI;
using System.Collections;
using System.Drawing;
public class Demo : MonoBehaviour
{
public Transform points;
private int destPoint = 0;
private NavMeshAgent agent;
void Start()
{
agent = GetComponent();
// Disabling auto-braking allows for continuous movement
// between points (ie, the agent doesn’t slow down as it
// approaches a destination point).
agent.autoBraking = false;
GotoNextPoint();
}
void GotoNextPoint()
{
// Returns if no points have been set up
if (points.Length == 0)
return;
// Set the agent to go to the currently selected destination.
agent.destination = points[destPoint].position;
// Choose the next point in the array as the destination,
// cycling to the start if necessary.
destPoint = (destPoint + 1) % points.Length;
}
void Update()
{
// Choose the next destination point when the agent gets
// close to the current one.
if (!agent.pathPending && agent.remainingDistance < 0.5f)
GotoNextPoint();
}
}