The Great Fleece: Coin Distraction, Part 1
Today I’ll be going over setting up a way Darren can toss a coin to distract one of the guards so that he can sneak by.
In the Project folder, there is a Coin_Drop sound effect and a Coin prefab. Those will be used as part of the coin distraction functionality.
Darren will be tossing the coin when the Player right-clicks on the mouse and will toss the coin when the mouse pointer is located when clicked. So first, we need to detect when the right mouse button is clicked. We do this with a simple Input check.
Next will be to create two Serialized GameObjects. One for the coin Prefab and the other for the sound effect.
Then in the Input check, a Raycast is used to determine where the Player has clicked since the coin will be instantiated at that location.
Then within the “if” check for the Raycast, the coin and the sound effect are instantiated using the hitInfo from the Raycast as a location. The Main Camera location is used for the coin sound effect to be heard better by the Player.
Currently, the Player can keep right-clicking to toss more coins. To prevent that, a new Boolean will be created and a check added to the mouse click check to see if the coin has already been tossed.
This is the first part of getting the coin distraction set up. Next will be having the guards move to the location where the coin has been tossed.
Until next time I wish you well on your coding and game development journey.