In this recipe, you created a small red 3D Sphere named Sphere-destination.
There is one public variable for the MoveToClickPoint scripted component of the Sphere-arrow GameObject. This public sphereDestination variable has been linked to the red Sphere-destination GameObject in the scene.
There are two private variables:
- navMeshAgent: This will be set to refer to the NavMeshAgent component of the Sphere-arrow GameObject so that its destination can be reset when appropriate.
- hit: This is a RaycastHit object that is passed in as the object to be set by Physics.Raycast(...). Various properties of this object are set after a raycast has been created, including the position in the scene where the raycast hits the surface of an object.
The Start() method caches a reference to the NavMesh component of the Sphere-arrow GameObject and also moves the Sphere-destination GameObject to the current object's location.
Each frame, in the Update() ...