当前位置:网站首页>脚本生命周期
脚本生命周期
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(),将对象变为不可用状态,然后再销毁
边栏推荐
- Ethernet port &arm & MOS &push-pull open drain &up and down &high and low sides &time domain and frequency domain Fourier
- [meisai] meisai thesis reference template
- 自动化测试的好处
- Ks003 mall system based on JSP and Servlet
- mysql关于自增长增长问题
- Codeforces Round #770 (Div. 2) B. Fortune Telling
- Basic concepts of LTE user experience
- WPF effect Article 191 box selection listbox
- 【PSO】基于PSO粒子群优化的物料点货物运输成本最低值计算matlab仿真,包括运输费用、代理人转换费用、运输方式转化费用和时间惩罚费用
- [Massey] Massey font format and typesetting requirements
猜你喜欢

User datagram protocol UDP

Basic knowledge of binary tree, BFC, DFS
![[meisai] meisai thesis reference template](/img/14/b39e1db0b5b35702508068e028ee5a.jpg)
[meisai] meisai thesis reference template

【leetcode】1189. Maximum number of "balloons"
![P7735-[noi2021] heavy and heavy edges [tree chain dissection, line segment tree]](/img/b1/dbfc42d66548476300501dd839abef.jpg)
P7735-[noi2021] heavy and heavy edges [tree chain dissection, line segment tree]

Stack and queue

cookie,session,Token 这些你都知道吗?

mysql从一个连续时间段的表中读取缺少数据

Custom event of C (31)

Containerization Foundation
随机推荐
DM8 backup set deletion
Hashcode and equals
Align items and align content in flex layout
[practical exercise] face location model based on skin color
【FPGA教程案例12】基于vivado核的复数乘法器设计与实现
[Key shake elimination] development of key shake elimination module based on FPGA
Conditionally [jsonignore]
ESP32(基于Arduino)连接EMQX的Mqtt服务器上传信息与命令控制
[matlab] - draw a five-star red flag
Global and Chinese market of aircraft anti icing and rain protection systems 2022-2028: Research Report on technology, participants, trends, market size and share
2.13 weekly report
Solution to the problem that the root account of MySQL database cannot be logged in remotely
Introduction to data types in MySQL
Benefits of automated testing
【可调延时网络】基于FPGA的可调延时网络系统verilog开发
潘多拉 IOT 开发板学习(HAL 库)—— 实验9 PWM输出实验(学习笔记)
User perceived monitoring experience
KS008基于SSM的新闻发布系统
On Data Mining
Flask learning and project practice 8: introduction and use of cookies and sessions