Coin Distraction Part 1

addam davis
3 min readSep 20, 2021

Objective: Create a coin where the player right-clicks!

A common mechanic in stealth games is the use of a distraction. In this tutorial we are going to create the function of having your player toss a coin to distract the enemies.

To begin I am going to use a coin model I already have. If you don’t have an asset for your coin you can use a 3D object and prefab it.

Open the player’s script and create a variable to hold your ‘coin’.

Now we want to instantiate this coin when we the right-click. So under the update method we want to add our input method.

Remember. Left click = 0 Right click =1 Mouse Wheel = 2

Now to place the coin where we click we are going to need to Raycast similarly to how we did for the point and click movement. For a deeper look into Raycasting you can go back to that tutorial.

Now where ever you right click your coin will appear.

We want to limit the amount of coins our player gets, for this tutorial I’m setting up one coin. To do this we need a bool variable to represent if the coin has been thrown or not.

The bool defaults to false and when we throw the coin want it to switch to true and if it’s true we cannot throw any more. Do this by adding the parameter that the bool is false to the if input statement. Once called, the code will turn the bool to true and thus the code can no longer be used.

Now you’ve created the coin toss function. In the next tutorial we will add the function for the guards to stop patrolling and head towards the coin. I’ll see you in the next tutorial!