当前位置:网站首页>脚本生命周期
脚本生命周期
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(),将对象变为不可用状态,然后再销毁
边栏推荐
- After five years of testing in byte, I was ruthlessly dismissed in July, hoping to wake up my brother who was paddling
- Record an excel xxE vulnerability
- 判断当天是当月的第几周
- 阿里测试师用UI自动化测试实现元素定位
- Align items and align content in flex layout
- Simple blog system
- Why do you want to start pointer compression?
- How do we make money in agriculture, rural areas and farmers? 100% for reference
- 有条件地 [JsonIgnore]
- [practice] mathematics in lottery
猜你喜欢

Ks003 mall system based on JSP and Servlet

Fundamentals of SQL database operation

MySql数据库root账户无法远程登陆解决办法

Esp32 (based on Arduino) connects the mqtt server of emqx to upload information and command control

Detailed explanation of serialization and deserialization
![Cf464e the classic problem [shortest path, chairman tree]](/img/6b/65b2dc62422a45cc72f287c38dbc58.jpg)
Cf464e the classic problem [shortest path, chairman tree]

C mouse event and keyboard event of C (XXVIII)

Network security - Security Service Engineer - detailed summary of skill manual (it is recommended to learn and collect)

math_ Derivative function derivation of limit & differential & derivative & derivative / logarithmic function (derivative definition limit method) / derivative formula derivation of exponential functi
![[introduction to Django] 11 web page associated MySQL single field table (add, modify, delete)](/img/8a/068faf3e8de642c9e3c4118e6084aa.jpg)
[introduction to Django] 11 web page associated MySQL single field table (add, modify, delete)
随机推荐
Blue Bridge Cup - day of week
Indicator system of KQI and KPI
UDP reliable transport protocol (quic)
Mapping between QoE and KQI
Python book learning notes - Chapter 09 section 01 create and use classes
Cf603e pastoral oddities [CDQ divide and conquer, revocable and search set]
JVM的手术刀式剖析——一文带你窥探JVM的秘密
【可调延时网络】基于FPGA的可调延时网络系统verilog开发
Database, relational database and NoSQL non relational database
Alibaba testers use UI automated testing to achieve element positioning
mysql关于自增长增长问题
cookie,session,Token 这些你都知道吗?
C mouse event and keyboard event of C (XXVIII)
如何修改表中的字段约束条件(类型,default, null等)
Ks003 mall system based on JSP and Servlet
Custom event of C (31)
Exchange bottles (graph theory + thinking)
math_极限&微分&导数&微商/对数函数的导函数推导(导数定义极限法)/指数函数求导公式推导(反函数求导法则/对数求导法)
【PSO】基于PSO粒子群优化的物料点货物运输成本最低值计算matlab仿真,包括运输费用、代理人转换费用、运输方式转化费用和时间惩罚费用
An article will give you a comprehensive understanding of the internal and external components of "computer"