Creating an Distraction (part 1)

Using a coin to create noise and Distraction against Guard AI

After creating the Guard AI movement and also having virtual eyes that the Guards can use to track the player, we can fully play the game at its intended capacity. Now it is good time to add some some game play features, such as tossing a coin as a distraction for the guards to be preoccupied with. To make this happen, we will required the “Player Script”, a “coin prefab” and also the “coin dropping SFX”.

Player Script

In the player script, we have already written the code for left mouse button click to move the player. Now we want to have the right mouse button click to instantiate the coin prefab along with sound effects.

Start by creating a public Game Object to hold the coin prefab. We are also going to create an Audio Clip handler as the same time so we can play an sound clip we instantiate the coin.

Then in the Update method we are going to create a new IF statement that tracks the Input of the right mouse button. Using “GetMouseButtonDown(1)” we are able to track the input devices.

tip: Remember that zero is for Left click and one is for Right click. Number two is for the mouse scroll wheel.

Next we are going to instantiate the coin prefab by using the Instantiate script. Following the same method as the Left click to move player, we are also going to use the same Ray Cast formula to target the location of where the coin drops.

Within the IF statement we are going to Instantiate the coin prefab using the hit Info variable as the location. Also within the same IF statement we are going to play an audio source clip at the player position.

Back in Unity, we will drag and drop the sound clip and coin prefab into the requested slots on the player script. Save and hit play and watch as you can summon gold coins everywhere

raining gold coins

A Designer, an Illustrator and a massive tech geek aspiring to become a professional Unity Developer.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Helping the government map the spread of COVID-19; An Inspiring Story of Marek and His team.

TCP Socket Connection and send Message iOS Swift ( IoT Hardware)

Why am I unable to preview 16-bit image data from my camera?

Connect to Remote Windows Server using psexec from JenkinsPipeline

What happen when you hit refresh on your computer screen?

High Efficiency Tool Platform for Framework Migration

What Is Xamarin.Forms? Understand Xamarin.Forms Before You Regret.

Dev’s on FHIR — Documents across the NHS (Part 3)

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Simon Truong

Simon Truong

A Designer, an Illustrator and a massive tech geek aspiring to become a professional Unity Developer.

More from Medium

Creating a Loot system (part 1)

Level Design in Unity Part 1: The Floor

Cleaning up the Homing Missile code

Using Decals in Unity