Using OnClick Events in Unity

2D Mobile Game

Objective: Create an OnClick event for the shop.

Create a switch case and define what each case does which in this case define the selected item and define the highlight position

Then when you press on buy item, the script will buy the one that was selected and remove gems with respect to the item and if the gem count is lower than the item price then the item is not bought.

Now in the inspector, select the UI Button and drag the gameobject where the script with cases were defined are stored and select the method which will respond to the button press.




Unity Developer

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

Recommended from Medium

Using Python Script in .NET Applications

{UPDATE} Permüt – Um novo quiz de figuras para jogar com seus amigos! Hack Free Resources Generator

Foreman,A Open Source Project


Waifusion Community Update: Edition 6

Core Performance Improvements, Webpack 5, React Native, and more in Nx 13!

Review effort estimation using Machine Learning

Community Update: Edition 1

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
Niraj Karki

Niraj Karki

Unity Developer

More from Medium

Using Light Probes in Unity’s HDRP

nitCreating Collectables in Unity

Quick and Easy: Alter Your Pre-Built Unity Texture Maps using Krita.

HitBox Attack System in Unity