CREATE YOUR WORLD
Scripting

EventTrigger

5min

The EventTrigger receives events from the Unity EventSystem and calls the registered functions.

To use the Unity EventTrigger in ZEPETOScript, you must follow the format given below.

First, for testing purposes, add UI > Panel to the Scene.

Document image




Click [Add Component] in the inspector of the added Panel, and add the Event Trigger component.

Document image




Example Script

First, import the classes related to the EventTrigger.

TypeScript


Write code to delegate the EventTrigger. Through the delegate, you can define callback methods and call methods on behalf of others.

👍 Concept of Delegate

  • A Delegate can be seen as a type of function pointer, which is an object that can reference and call a function.
  • It can pass or return a function like a variable, and can also be passed as a parameter to other functions.
  • In Unity, delegates are widely used for event handling. For example, you can connect a method to a delegate to have it automatically called whenever a specific event occurs.



TypeScript




Refer to the screen shown below.

Document image




Check the full code example for Event Trigger.

EventTriggerSample




You can learn more about types of events supported by Unity and the EventTrigger by clicking the links below.



Updated 10 Oct 2024
Doc contributor
Did this page help you?