Guides
Log In

Event Trigger

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, import the classes related to the EventTrigger.

import { EventTrigger, EventTriggerType } from 'UnityEngine.EventSystems';
import { Entry } from 'UnityEngine.EventSystems.EventTrigger';

Then, write the code to delegate the EventTrigger.

Start() {
    const trigger = this.gameObject.GetComponent<EventTrigger>();

    // Create eventsystem entry
    const entry = new Entry();

    // Specify event type & delegation
    entry.eventID = EventTriggerType.PointerClick;
    entry.callback.AddListener(() => {
        console.log("click")
    });

    // Register event entry
    trigger.triggers.Add(entry);

}

Refer to the screen shown below.

1179

Check the full code example for Event Trigger.

import { ZepetoScriptBehaviour } from 'ZEPETO.Script';
import { EventTrigger, EventTriggerType } from 'UnityEngine.EventSystems';
import { Entry } from 'UnityEngine.EventSystems.EventTrigger';
 
export default class EventTriggerSample extends ZepetoScriptBehaviour {

    Start() {
        const trigger = this.gameObject.GetComponent<EventTrigger>();

        // Create eventsystem entry
        const entry = new Entry();

        // Specify event type & delegation
        entry.eventID = EventTriggerType.PointerClick;
        entry.callback.AddListener(() => {
            console.log("click")
        });

        // Register event entry
        trigger.triggers.Add(entry);

    }
}

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



πŸ“˜

Supported events

https://docs.unity3d.com/kr/current/Manual/SupportedEvents.html

πŸ“˜

EventTrigger

https://docs.unity3d.com/kr/530/ScriptReference/EventSystems.EventTrigger.html