Create a Coin Distraction Feature in Unity (Part 2)

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.

--

--

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