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.



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.