Create a coin distraction system in Unity Part 1
Objective: Instantiate a coin at click position and play coin sound
When the player right-clicks they will be able to ‘throw’ a coin and distract the guards so that they can get past them to the vault.
This is going to work in an identical fashion to how the click and move system for the player works. In fact, the only difference is that we’re not moving the player and instead are just spawning a coin prefab where the player has clicked.
I created a bool to only allow the player one throw of the coin for the time being. I am then using a raycast to get the position of the mouse in world coordinates, then checking whether the raycast has hit anything.
I then set the bool to true, this is disable the coin throw for the player and then spawn a coin prefab and play a sound at the coin position.
Come back for the next article where I will be getting the guards to move to the coin position to investigate.