Custom Scripts
Learn how to link your custom code to Triggers and Actions
Introduction
Using Triggers to execute Custom Code
// @ts-nocheck
import { Script } from 'playcanvas';
import { TriggerDispatcher } from '../.viverse/toolkit/extension.mjs';
export class TriggerHandler extends Script
{
static scriptName = 'Trigger Handler';
initialize ()
{
// Retrieve singleton instance of TriggerDispatcher
this.dispatcher = TriggerDispatcher.getInstance ();
// Use .on or .once to subscribe to your custom trigger events
// Note how full event id is retrieved via .getTriggerEventName first
this.dispatcher.on
(
this.dispatcher.getTriggerEventName ('some.trigger.name'),
this.onTriggerActivated,
this
);
}
// Your custom code can be placed here
onTriggerActivated ()
{
alert ('Custom code executed!');
}
}Executing Actions from Custom Code
Last updated
Was this helpful?