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

Set up a Hadoop Cluster using Ansible

Manta Network: Parachain Next Steps

New Streamlabs Desktop Audio Settings Redesign

Why Headless Is the Future of Mobile Development

Go MetaRail and EFUN Announce Strategic Partnership

Loading a scene in Unity

Firebase Firestore unit testing with jest (and kind of typescript)

What is ‘ContentOps’ and why should you invest in it?

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

HitBox Attack System in Unity

2D Homing Missile in Unity

Converting from 3D to 2D in Unity

Understanding Frustum and Occlusion Culling in Unity3D