OnClick Events in Unity

Using Unity UI Buttons to Interact with the Player

When Creating a UI in Unity you can add a Button.

In order to Interact with the Button Unity Provides a On Click Unity Event that you can register to.

An Unity Event can run any public Method or Change any public Property on any GameObject Components in the Scene.

I have a method for Selecting an Item in my Shop and For Buying an Item in my Shop in my Unity Manager on my Canvas.

To assign these all I need to do is click the plus button on each of my Buttons On Click Event and select what I want to do.

Now when I click on the Buttons the On Item Selected and Buy Item will run.

--

--

--

Excited about changing my hobby into a new carer with GameDevHQ course.

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

Recommended from Medium

Music with code: Getting Started with Sonic Pi

Sum subarrays of a Matrix.

HOW TO SUCCESSFULLY PLEDGE MINING ON THINKIUM CHAIN

Tilemap — Using Tilemap in Unity — part 1

How do I use JWT Authentication in production?

Development of a payment acceptance system:

CAD Files and How to Convert from One to Another

CS373 Fall 2021: Thomas Connor Thompson

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
James Lafritz

James Lafritz

Excited about changing my hobby into a new carer with GameDevHQ course.

More from Medium

Cleaning up the Homing Missile code

How to Switch Between Cameras with Cinemachine and Timeline

My journey becoming a Unity game developer: 2.5D Infinite Runner-Moving Platform with player

Creating a Game Manager