Basic functions commonly used in Unity


Awake(): Called when the current control script instance is loaded, often used for initialization;

start(): Called before the current control script executes Update() for the first time;

Update(): execute once per frame;

FixedUpdate(): Execute once every fixed frame drawing. The difference from Update() is that FixedUpdate() is executed on the rendering frame. If the rendering efficiency is low, the number of calls to FixedUpdate() will decrease accordingly. FixedUpdate() is more suitable for the calculation of the physics engine, and Update() is more suitable for control.

LateUpdate(): It is called after the execution of each frame, that is, it is called after all Update()s are completed, which is more suitable for the execution of command scripts. It is often used to follow the camera, that is, follow up the camera after all operations are completed, otherwise it is easy to appear that the camera has already followed up, but there are still some operations in the scene that have not been executed.

Reset(): Called when the reset button is clicked in editor mode, often used for debugging initialization;

OnBecameInvisible(), OnBecameVisible(): called when the script host is (not) displayed by any camera;

OnCollisionEntry(), OnCollisionExit(), OnCollisionStay(): call when detecting collision between two colliders , exiting collision, and staying;

OnTriggerEntry(), OnTriggerExit(), OnTriggerStay(): call when two triggers collide, exit the collision, or stay;

OnParticleCollision(): Triggered when a particle hits a collider;

OnDisable(), OnEnable(): Triggered when the script host is enabled or disabled;

OnGUI(): Triggered when the GUI is drawn, generally used to draw the GUI menu;

Mouse listener event, triggered when the mouse interacts with the GUI or collider:

OnMouseDown(): Triggered when the mouse is pressed;

OnMouseDrag(): When the mouse is pressed, it will be called every frame;

OnMouseUp(): Triggered when the mouse is lifted;

OnMouseEnter(): Move the mouse up to trigger;

OnMouseExit(): Triggered when the mouse moves out;

OnMouseOver(): Triggered every frame when the mouse is on the game object.

OnApplicationFocus(), OnApplicationPause(), OnApplicationQuit(): Called when the application loses focus, pauses, or exits;

OnConnectedToServer(), OnDisconnectedFromServer(): Called when connecting/disconnecting the server;

OnFailedToConnect(), OnFailedToConnectToMasterServer(): Called when the connection fails.

Life cycle of basic functions in Unity

insert image description here

Guess you like

Origin blog.csdn.net/qq_33021529/article/details/125729441