The Great Fleece: Point & Click Movement, Part 3
Now that the scripting to determine the coordinates when the screen is left-clicked is completed, it’s time to have the Player actually move.
First, a handle to the NavMesh Agent on the Player needs to be created.
Also, make sure to add the UnityEngine.AI namespace at the top like below.
Next, in the Start() method, the _agent is set to the NavMeshAgent on the player using GetComponent.
Now that a handle is assigned, it can be used to set the destination in the Update() method when the mouse is left-clicked. First, I’ll remove the code for creating the cube and replace it with a SetDestination() method, which takes a Vector3 point to move the NavMeshAgent. So the new code will look like this.
Now the player should move to wherever we click in the game.
Well, the player is moving where the mouse is clicked. But it is also clipping through objects on the way to the clicked point. So, in the next article, I’ll go over fixing the clipping issue, which should finish off the basics of the point-and-click movement for the player.
Until next time I wish you all success and good luck in your coding and game development journey.