I trying to build a point and click system where the point i click will become destination point for the NavMeshAgent. Here is the code i am using:
if (Input.GetKey (KeyCode.Mouse0)) {
ray = characterCamera.ViewportPointToRay (Input.mousePosition);
didHit=Physics.Raycast (ray, out hit);
Debug.Log (didHit.ToString ());
Debug.DrawRay (ray.origin,ray.direction,Color.red,30f);
if (didHit) {
rayHitPosition=hit.point;
currentMarker=Instantiate (Marker,rayHitPosition,Quaternion.Euler (Vector3.zero));
}
My floor is a basic plane with a plane collider. This code always shows didHit false even if i am obviously pressing on the plane. Even Debug.DrawRay doesn’t draw anything even though debugging shows ray variable does contain a valid ray. characterCamera is my main camera.