当前位置:网站首页>Script lifecycle

Script lifecycle

2022-07-06 04:05:00 A plum in fall


Preface

MonoBehaviour Class defines a script file to be loaded from the beginning , To the final destruction of a complete process . This process , Through corresponding methods , Perform functions that cannot be done in different ways .
We call these methods : Methods related to script life cycle .


One 、 Initialize the relevant methods

Awake()

Called automatically when the script is loaded into the scene
Only execute once in the whole life cycle

OnEnable()

Called when the object becomes available or active , Determine whether the object or script is available
coordination OnDisable() Methods used together
The number of executions is uncertain

Start()

for the first time Update Previous call
Only execute once in the whole life cycle , Used for initialization

Two 、 Update relevant methods

FixedUpdate()

Fixed update
Refresh the scene in frames , Refresh at fixed intervals
Physical related update operations , Put it in FixedUpdate() complete

Update()

to update
The execution time of each frame may be inconsistent with that of each frame
Update() The execution rate is related to hardware devices and rendered objects , Sometimes fast, sometimes slow
It mainly completes the update of data in the scene and the logical processing of data

LateUpdate()

Update later
When a frame execution ends , Before preparing for the next frame execution , This method is called

OnGUI()

Rendering and processing GUI event

3、 ... and 、 Destruction related methods

OnDisable()

When an object or script is unavailable ( Or inactive ) When the
Execute several times indefinitely
It's usually related to OnEnable() In combination with

OnDestory()

Only execute once in the whole life cycle
Be the object ( Script files ) Only execute this method when destroyed
Generally, it will be executed first OnDisable(), Make the object unavailable , And then destroy

原网站

版权声明
本文为[A plum in fall]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/187/202207060401188127.html