I seriously can't figure out how to use this function, and the documentation doesn't help at all.
Here's the documentation code:
public class ExampleClass : MonoBehaviour {
public Transform target;
private NavMeshAgent agent;
void Start() {
agent = GetComponent<NavMeshAgent>();
NavMeshPath path;
agent.CalculatePath(target.position, path);
if (path.status == NavMeshPathStatus.PathPartial) {
}
}
}
Here's my code:
public class Movement : MonoBehaviour {
NavMeshAgent agent;
NavMeshPath path;
void Start () {
agent = GetComponent<NavMeshAgent>();
}
void MoveToTargetLocation() {
agent.SetDestination(targetLocation); <-- being set somewhere else
NavMeshPath path;
agent.CalculatePath (targetLocation, path);
if (path.status != NavMeshPathStatus.PathPartial) {
if (Vector3.Distance (curLocation, targetLocation) > 0.55) {
animation.CrossFade (animationRun.name);
moving = true;
} else {
animation.CrossFade (animationIdle.name);
moving = false;
}
}
}
}
The error I'm receiving is:
Assets/Movement.cs(59,54): error CS0165: Use of unassigned local variable `path'
Am I supposed to be setting the path somewhere else?