OnClick Events in Unity

I’m working with the UI of the mobile project for the management of the shop I’ve realized a system that allows you to select an item on the screen and buy it by pressing the “Buy Item” button.

To realize the selection and the purchase the use of the unity system linked to the inspector for the management of OnClick events is essential.

I can realize simple script functions associated with a GameObject in the scene and then insert it as behavior inside a button of my UI.

Let me explain, in my script I have written a function.

You have to select the GameObject with the assigned script and insert it in the listener of the button, the methods to be visible must be public.



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