Create a Coin Distraction Feature in Unity (Part 2)

Limiting the quantity of coins the player can toss

Rusben Guzman
Nov 30, 2021

Objective: create a code to limit the quantity of coins a player can toss.

In the player script let’s create an int variable to represent the quantity of coins the player has available.

In the update method we have to check before instantiate the coin if the player have more than 0 coins, if it’s true we can instantiate the coin and decrease the coins variable.

And that’s it!!! When the player has 0 coins you can make a right click but no coin is going to be instantiated.

--

--

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.