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.

An Integer of 1 is used for the Right Mouse Button.

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.

--

--

--

I'm a Unity developer.

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

Recommended from Medium

How to Succeed When Outsourcing App Development

App Development Outsourcing

LinkedIn Hakawai. Implement user mentions feature in your iOS Swift application.

Cloud Security Posture Management

Cosmicast 2.0: This Post Should’ve Been a Podcast Episode

List Methods in Python

Linux Privilege Escalation By Using SUID

Google Code-In 2017, A Look Back

Find the Sum of the series: 1+1/2+1/3..+ 1/N in Python

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
Brian Branch

Brian Branch

I'm a Unity developer.

More from Medium

Creating An fbx Emission Layer For Unity Using Photoshop & Blender

How To Upgrade Your Project to URP in Unity

Playmaker?

Creating a triple shot for my Player