Creating Coin Distraction Feature in Unity (Part 1)

Objective: Instantiate a coin prefab on player right click position.

In this part we are going to create a code to instantiate a coin prefab when the player makes a right click and play the drop coin audio.

In the player script we have to create a variable to store the coin prefab and assign it in the inspector.

I added an audiosource component to the coin prefab and assigned the drop coin audio to it. Also I left the play on awake property checked.

Last thing is in the script player check for the right click, then create a ray from the mouse click position and if the raycast detects the floor we instantiate the coin prefab in the hit point position.

And that’s it!!! When the player makes a right click, a coin prefab is instantiated in the click position.

--

--

--

A Software Engineer passionate about game dev and interactive products with Unity. I consider video games to be the artistic expression of programming.

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

Recommended from Medium

Binary Search In Action

Systematically Troubleshooting Production Issue/Outage

Adding Boss Damage VFXs in Unity

There are No Stupid Questions, Just Insecure Developers

5 CSS rules you might not know

Get Komoot tour data without API

HNGi8 Internship

This F**king Noise, You Know ¹

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
Rusben Guzman

Rusben Guzman

A Software Engineer passionate about game dev and interactive products with Unity. I consider video games to be the artistic expression of programming.

More from Medium

Creating a Physics Based Character Controller in Unity

Using Light Probes in Unity’s HDRP

Creating Rewarded Video Ads in Unity

Drone Controls w/ New Unity Input System