Definition
function OnTriggerEnter(otherActorName) end
Description
This event is specific to the trigger object. Suppose a script that has an OnTriggerEnter(otherActorName) event is attached to a trigger object. In this case, the OnTriggerEnter(otherActorName) event is called once when the main character or a prefab instance that has dynamic physics enters the trigger.
Parameter
otherActorName
This parameter is automatically sent to OnTriggerEnter event by Vanda engine. If a prefab instance that has dynamic physics is entered into the trigger, the name of its physics actor is sent to the OnTriggerEnter event. If the main character of the game enters the trigger, the value nil is sent to the OnTriggerEnter event.
Example 1
function OnTriggerEnter(otherActorName) PrintConsole("\nOnTriggerEnter() Event was called") end
Assume that this script is attached to a trigger called “trigger1”. In this case, if the main character or a prefab instance that has dynamic physics is entered into “trigger1”, the message “OnTriggerEnter() Event was called” will be displayed.
Example 2
function OnTriggerEnter(otherActorName) if otherActorName == nil then PrintConsole("\nMain character entered the trigger and OnTriggerEnter() Event was called") else prefab_instance_name = GetPrefabInstanceNameFromActor(otherActorName) message = string.format("\nOnTriggerEnter() Event was called. Prefab instance name is : %s" ,prefab_instance_name) PrintConsole(message) end end
Assume that this script is attached to a trigger named “trigger1”. In this case, if the main character is entered into “trigger1”, the message “Main character entered the trigger and OnTriggerEnter() Event was called” will be displayed. Otherwise, if a prefab instance that has dynamic physics is entered into this trigger, the name of its physics actor is sent to the OnTriggerEnter event. Using the GetPrefabInstanceNameFromActor function, we find the prefab instance name that otherActorName name belongs to and display it in the console.
OnTriggerEnter Event