当前位置:网站首页>脚本生命周期
脚本生命周期
2022-07-06 04:01:00 【A plum in fall】
文章目录
前言
MonoBehaviour类定义了一个脚本文件从最初被加载,到最后被销毁的一个完整过程。这个过程,通过对应的方法体现出来,在不同的方法中完成不能的功能。
我们把这些方法称为:脚本生命周期相关的方法。
一、初始化相关的方法
Awake()
脚本被加载到场景中时自动调用
整个生命周期中只执行一次
OnEnable()
当对象变为可用或激活状态时调用,判断对象或脚本是否可用
配合OnDisable()方法一起使用
执行次数不确定
Start()
第一次Update之前调用
整个生命周期中只执行一次,用于进行初始化
二、更新相关的方法
FixedUpdate()
固定更新
以帧为单位进行场景的刷新,以固定的时间隔来进行刷新
与物理相关的更新操作,放在FixedUpdate()完成
Update()
更新
每一帧与每一帧的执行时间可能是不一致的
Update()执行速率与硬件设备和被渲染物体有关系,有时快有时慢
主要完成场景中数据的更新和数据的逻辑处理操作
LateUpdate()
晚于更新
当一帧执行结束,在准备下一帧执行之前,会调用该方法
OnGUI()
渲染和处理GUI事件
三、销毁相关的方法
OnDisable()
当对象或脚本处于不可用(或不可激活)时执行
执行几次不确定
一般会与OnEnable()配合使用
OnDestory()
整个生命周期中只执行一次
当对象(脚本文件)被销毁时只执行该方法
一般会先执行OnDisable(),将对象变为不可用状态,然后再销毁
边栏推荐
- Viewing and verifying backup sets using dmrman
- 【可调延时网络】基于FPGA的可调延时网络系统verilog开发
- Conditionally [jsonignore]
- Fundamentals of SQL database operation
- [Massey] Massey font format and typesetting requirements
- Oracle ORA error message
- AcWing 243. A simple integer problem 2 (tree array interval modification interval query)
- C language -- structs, unions, enumerations, and custom types
- [prediction model] difference method model
- Ipv4中的A 、B、C类网络及子网掩码
猜你喜欢
Développement d'un module d'élimination des bavardages à clé basé sur la FPGA
[practice] mathematics in lottery
Stack and queue
cookie,session,Token 这些你都知道吗?
在 .NET 6 中使用 Startup.cs 更简洁的方法
ESP32(基于Arduino)连接EMQX的Mqtt服务器上传信息与命令控制
Facebook等大厂超十亿用户数据遭泄露,早该关注DID了
[Massey] Massey font format and typesetting requirements
Multi project programming minimalist use case
Class A, B, C networks and subnet masks in IPv4
随机推荐
No qualifying bean of type ‘......‘ available
Esp32 (based on Arduino) connects the mqtt server of emqx to upload information and command control
On Data Mining
How can programmers resist the "three poisons" of "greed, anger and ignorance"?
RT thread -- FTP of LwIP (2)
How does technology have the ability to solve problems perfectly
Align items and align content in flex layout
【leetcode】22. bracket-generating
Exchange bottles (graph theory + thinking)
Determine which week of the month the day is
Pandora IOT development board learning (HAL Library) - Experiment 9 PWM output experiment (learning notes)
C#(三十一)之自定义事件
Custom event of C (31)
asp. Core is compatible with both JWT authentication and cookies authentication
Basic concepts of LTE user experience
C (thirty) C combobox listview TreeView
[practice] mathematics in lottery
Plus d'un milliard d'utilisateurs de grandes entreprises comme Facebook ont été compromis, il est temps de se concentrer sur le did
cookie,session,Token 这些你都知道吗?
Differential GPS RTK thousand search