I didn't verify it! ~~~~~
Please poke: Figure out how these functions are called in the script
Call to start and awake functions when the game object is active or if the script is enabled
There are basically four scenarios:
1.game object is active but script is disabled
At this point, only the awake function is called immediately when the object is created, and onenable and Start are called after the enabled script.
2.game object is deactive but script is enabled
At this point, when the object is created, no function is called, and the function is called after the active object in awake onenable Start order.
3.game object is avtive and script is enabled
At this point, when the object is created, it executes the function in Awake onenable start order.
The 4.game object is deactive and the script is disabled
There is no function call to create the object at this time, and the awake function is called immediately after the active object, and onenable and start are then called after the enabled script.
It is important to note that awake and start are called only once in the life cycle of a game object, but Onenable is executed again every time the script is activated.
If you create an object in the game and activate its script, then awake onenable Start will be called, and a script with the enabled set to False will ondisable be called
, Onenable will be called again when it is activated again awake and Start will not be called again. Note When a game object is setactive (false), its binding script and ondisable in the sub-script are also
will be called, SetActive (True) when the onenable is called. This can explain why you would write code in their onenable and ondisable OnDestroy when subscribing to and removing event delegates for a game object.
, I did not understand this before.
"Go" to figure out how these functions are called in the script.