1, study notes, every night to see the Unity 3d Tutorial Learn something, first on a picture this is the system of script execution sequence diagram
Awake () is called immediately after Monobehavior is created, and the awake function executes only once during the entire life cycle of the script instance, and if the initial state of the game object (that is, gameobject) is off, the awake function does not execute If the initial state of the game object is on, the awake function executes; it is important to note that the execution of the awake function is not related to the state of the script instance (enabled or disabled), but rather to the switching state of the game object that the script instance is bound to. If you reload the scene, the execution of the awake function in the scene re-follows the two points above. Some initialization operations can be done
Start () is called after the Monobehavior is created before the first execution of the frame update (), and the start () function executes only when the script instance is enabled; the start function is always executed after the awake function. If the game object is turned on, the script instance bound on the object is disabled, then the start function will not execute. This is the feature of the start function, which executes only when the script instance is enabled, and the start function only executes when the script instance is first opened. If a script instance that has already been turned on is turned off and turned on again, the start function will not be executed again.
In general development, you get information about a game object or a script instance in the Awake function, and then do some initialization settings after getting it in the start function.
The public field is placed in the awake class.
Awake, onenable, and start are all methods that are called before the game starts running. It is called every time the script is activated, but start will be called before the first call to update!
Gameobject activity is true, when the script's enable is true, its sequence is: Awake, onenable, Start;
Gameobject activity is true, when the script's enable is false, only the awake is run;
Gameobject activity is false, none of the above is called, ondisable () is called;
Ondisable () script does not work with game object is activity is false
Ondestory: Called when an object is deleted. Or when the script component is removed and executed when the object is destroyed
Update: When Monobehaviour is enabled, its update is called at each frame, and the logic used to process the screen
Lateupdate: When behaviour is enabled, its lateupdate is called at each frame
Fixedupdate: This function is called once per fixed physical time slice. This is where the basic physical behavior Code of the game is placed. Called after update.
Reset:reset is called when the user taps the reset button on the inspector or when the component is first added. This function is called only in edit mode. Reset is most commonly used to give the most common default value in the Inspector.
Ongui: This function will be called several times per frame (once per event), GUI display function can only be called in Ongui
Unity 3d Scripting Common events