I want to make RTS game for test.But there is a error(NullReference Exception) that I face to face with every time while making click-to-move system.Here is my code:
public class Movement : MonoBehaviour {
NavMeshAgent agent;
// Use this for initialization
void Start () {
agent = GetComponent<NavMeshAgent>();
}
// Update is called once per frame
void Update () {
if (Input.GetMouseButtonDown(0))
{
RaycastHit hit;
if(Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 100)); //---Unity says that error is in this line!
agent.destination = hit.point;
}
}
}