CREATE YOUR WORLD
Scripting
Event Functions
9min
event functions are special functions automatically called during the life cycle of a gameobject or component in the unity engine, therefore, they are also referred to as lifecycle event functions event functions are automatically called by the unity engine at specific timings event functions are special functions automatically called during the life cycle of a gameobject or component in the unity engine, hence they are also referred to as lifecycle event functions zepeto script lifecycle flowchart initialization events you can use an initialization event to call the initialization code before an update the start function is called before any physics update and before the first frame, while the awake function is called for each object in the scene when calling up a scene start and awake functions for various objects are called in random order, but all awake calls are finished before start is called this means that the start function can use other initializations previously carried out in the awake function regular update events regular updates refers to all updates called every frame they change the position, state, and behavior of objects before each frame is rendered zepetoscript provides a guideline for processing the computation in the update function physics events physics events call event functions through a script added in the gameobject the oncollisionenter, oncollisionstay, and oncollisionexit functions are called as contact is made, held, and broken the ontriggerenter, ontriggerstay and ontriggerexit functions are called when an object collider is configured as a trigger (i e a collider that does not react physically to collisions but simply detects them instead) such functions may be called several times in succession if multiple contacts are detected during the physics update, and thus parameters are sent to the function that provides details of the collision (position, identity of the object) gui events zepetoscript supports events that render gui controls and reacts to clicks from the elements they work differently from normal frame updates, so ui related logic should be placed in the ongui function mouse events in zepetoscript, events that respond to mouse interactions are supported however, mouse events require a collider or collider2d to be present on the relevant gameobject, and they are only triggered when that collider is clicked with the mouse onmousedown() is called when the user clicks the mouse button onmouseup() is called when the user releases the mouse button onmouseover() is called every frame while the mouse cursor is over the collider or collider2d of the gameobject termination events termination events are called in all activated objects in a scene the ondisable function is called when a given object is disabled or is inactive, and onapplicationquit is called on all gameobjects before the application closes 📘 unity event functions https //docs unity3d com/kr/current/manual/eventfunctions html https //docs unity3d com/kr/current/manual/eventfunctions html all the event functions inherently supported by zepetoscript are listed in the sample code below sample monobehaviourlifecycle import { zepetoscriptbehaviour } from 'zepeto script'; import { collider, collider2d, collision, collision2d } from 'unityengine'; export default class samplemonobehaviourlifecycle extends zepetoscriptbehaviour { awake() { console log('awake '); } onenable() { console log('onenable '); } start() { console log('start '); } update() { console log('onupdate '); } fixedupdate() { console log('fixedupdate '); } lateupdate() { console log('lateupdate '); } ondisable() { console log('ondisable '); } ondestroy() { console log('ondestroy '); } ontriggerenter(coll collider) { console log(`ontriggerenter ${coll gameobject name} `); } ontriggerexit(coll collider) { console log(`ontriggerexit ${coll gameobject name} `); } ontriggerstay(coll collider) { console log(`ontriggerstay ${coll gameobject name} `); } ontriggerenter2d(coll collider2d) { console log(`ontriggerenter2d ${coll gameobject name} `); } ontriggerexit2d(coll collider2d) { console log(`ontriggerexit2d ${coll gameobject name} `); } ontriggerstay2d(coll collider2d) { console log(`ontriggerstay2d ${coll gameobject name} `); } oncollisionenter(coll collision) { console log(`oncollisionenter ${coll gameobject name} `); } oncollisionexit(coll collision) { console log(`oncollisionexit ${coll gameobject name} `); } oncollisionstay(coll collision) { console log(`oncollisionstay ${coll gameobject name} `); } oncollisionenter2d(coll collision2d) { console log(`oncollisionenter2d ${coll gameobject name} `); } oncollisionexit2d(coll collision2d) { console log(`oncollisionexit2d ${coll gameobject name} `); } oncollisionstay2d(coll collision2d) { console log(`oncollisionstay2d ${coll gameobject name} `); } ongui() { console log('ongui '); } onmousedown() { console log('onmousedown '); } onmousedrag() { console log('onmousedrag '); } onmouseup() { console log('onmouseup '); } onmouseenter() { console log('onmouseenter '); } onmouseexit() { console log('onmouseexit '); } onmouseover() { console log('onmouseover '); } onmouseupasbutton() { console log('onmouseupasbutton '); } onanimatorik(layerindex number) { console log(`onanimatorik ${layerindex} `); } onapplicationfocus() { console log('onapplicationfocus '); } onapplicationpause() { console log('onapplicationpause '); } onapplicationquit() { console log('onapplicationquit '); } } check out the test code output screen below you can learn more about the unity event functions that zepetoscript offers by clicking the links below 📘 order of execution for event functions https //docs unity3d com/kr/current/manual/executionorder html https //docs unity3d com/kr/current/manual/executionorder html