EDIT: This is different from other questions because the code is much more specific to NavMesh code. I haven't found any questions specific to my code. (also other question seems to involve null?)
I'm trying to learn NavMeshAgent for use in point and click movement for a game using RTS style movement. I keep getting errors. The first issue is "Load Failed: Object reference not set to an instance of an object" - my code is below.
using UnityEngine;
using System.Collections;
public class PlayerNavigation : MonoBehaviour {
public Camera cam;
public NavMeshAgent navMeshAgent;
void Start () {
cam = Camera.main;
navMeshAgent = GetComponent<NavMeshAgent>();
}
void Update () {
if(Input.GetKeyDown (KeyCode.Mouse0)){
Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
RaycastHit hit;
if(Physics.Raycast( ray, out hit)){
navMeshAgent.SetDestination ( hit.point );
}
}
}
}
My next issue, seems to be compiling error. I'm hoping fixing the above code will fix it. When I press play, it says "All compiler errors have to be fixed before you can enter playmode"
Any help would be greatly appreciated.