Good day to all readers! Not so long ago, I published
an article covering some of the commonly used scripting features of the Unity3d engine. In this part I would like to write about scripted events triggered under various conditions. All specified in this part of the directory, functions are available in any script that is “hung” on the game object.
Script Events
When developing on Unity3d, it is often necessary to tie the execution of its functions to a specific event. In Unity3d, there are quite a few such events, in this section I will try to describe the most used ones.')
This function is called each time before displaying the next frame. Most used to calculate game parameters. But it is absolutely not recommended to use the calculation of physical indicators in it.
Update()
This function is called each time the physical indicators are calculated. All calculations of physics should be carried out in it.
FixedUpdate()
This function is called after the execution of the script function Update ().
LateUpdate()
The trigger zone is an object for which the isTrigger property is set to true. GameObject.collider.isTrigger = true;
When specifying this property, the object is ignored by the physics engine and is used only as an event initialization.
All functions related to the contact of objects, or the intersection of a trigger zone by an object, take as a parameter an object of the class Collider, containing information about the object with which the interaction occurred.This function is called whenever the physical body enters the trigger zone.
OnTriggerEnter(collider:Collider)
This function is called each time the physical body leaves the trigger zone.
OnTriggerExit(collider:Collider)
This function is called continuously while the physical body is inside the trigger zone.
OnTriggerStay(collider:Collider)
This function is called every time one physical body enters another physical body.
OnCollisionEnter(collider:Collider)
This function is called each time when one physical body leaves another physical body.
OnCollisionExit(collider:Collider)
This function is called continuously, as long as one physical body is inside another physical body.
OnCollisionStay(collider:Collider)
This function is called before all other scripts are initialized. Typically used to set certain parameters and initialize variables.
Awake()
This function is called before the first start of any Update functions, but after executing the Awake () function.
Start()
This function resets values ​​to default values. Used only in edit mode.
Reset()
This function is called when the mouse cursor enters a game object, or an instance of a GUIElement object (game interface).
OnMouseEnter()
This function is called when the mouse cursor leaves the game object or the instance of the GUIElement object.
OnMouseExit()
This function is called continuously while the mouse cursor is on the game object, or on the game interface element.
OnMouseOver()
This function is called when a mouse button is pressed on a game object or a game interface element.
OnMouseDown()
This function is called when the mouse button is released, after clicking it on the game object or element of the game interface.
OnMouseUp()
This function is called if the player moves the mouse cursor away from the object or element of the game interface, after holding down the mouse button.
OnMouseUpAsButton()
This function is called when the mouse cursor is located with the button pressed on the game object or the game interface element.
OnMouseDrag()
The physical connection between objects is usually used to create mobile connections between objects.
Called when the physical connection between game objects is broken. After breaking the connection - it is automatically removed from the game. Gets as a parameter the force that caused the connection to break as a floating point number.
OnJointBreak(force:float)
This function is called when loading the game level (scene). Gets the sequence number of the loaded scene as a parameter, as an integer.
OnLevelWasLoaded(level:int)
This function is called if the object is in the field of view of at least one camera. It is convenient to use to disable game objects that are not visible to the player for optimization purposes. Of course, if there is no need to continue performing actions even if the object is hidden.
OnBecameVisible()
This function is called if the object is not in the field of view of any camera.
OnBecameInvisible()
This function is called when the object is activated (turned on).
OnEnable()
This function is called when the object is disabled.
OnDisable()
This function is called when an object is destroyed.
OnDestroy()
This function is called before determining the list of objects that will be rendered in the frame.
OnPreCull()
This function is called before rendering the scene in the frame.
OnPreRender()
This function is called after rendering the scene in the frame.
OnPostRender()
This function is called at the time of rendering the current game object in the scene.
OnRenderObject()
This function is called only once for each camera during the first rendering of the game object.
OnWillRenderObject()
This function is used to draw elements of the game interface and trigger events associated with it.
OnGUI()
This feature allows you to send a pause signal to all game objects. Accepts as a parameter a boolean value that identifies the pause state.
OnApplicationPause(pause:boolean)
This function is called upon receiving or losing the focus of the game window. Gets a boolean value that defines the current state as a parameter.
OnApplicationFocus(focus:boolean)
This function is called when you exit the game.
OnApplicationQuit()
In this reference manual, far from all the script events present in the game engine are covered. For example, events related to the network I left on one of the following articles, which will cover the description of working with the network.
I took descriptions of some of the functions from the Script Reference, so if you find it incorrect, please write to me about it, I will correct it.
Thank you for taking the time to read the article, I will be very happy if she helped someone.