Point-and-click move to object
Another way to choose the destination for our Sphere-arrow
GameObject is by the user clicking on an object on the screen, and then the Sphere-arrow
GameObject moving to the location of the clicked object:

Getting ready
This recipe adds to the first recipe in this chapter, so make a copy of that project folder and do your work for this recipe with that copy.
How to do it...
To create an object-based point-and-click mini-game, do the following:
- In the
Inspector,
add thePlayer
Tag to theSphere-arrow
GameObject. - Delete the two 3D
Cubes
and the 3DCapsule-destination
from the scene. - Create a
ClickMeToSetDestination
C# script-class containing the following:
using UnityEngine; public class ClickMeToSetDestination : MonoBehaviour { private UnityEngine.AI.NavMeshAgent playerNavMeshAgent; void Start() { GameObject playerGO = GameObject.FindGameObjectWithTag("Player"); playerNavMeshAgent = playerGO.GetComponent<UnityEngine.AI.NavMeshAgent>(); } private void OnMouseDown...