OnClick events in Unity
Sep 8, 2021
--
When creating buttons in Unity, there is a component that can be used to trigger events or methods when clicking on it: OnClick()
To use it:
- Click on the + icon. None (Object) is requiring a gameobject
- For our project, drag and drop the Shop_Keeper gameobject. It contains the
Shop
class with theSelectedItem(int)
method.
This method will be executed each time the Button gameobject is clicked
Also it allows you to add more scripts and methods