当前位置:网站首页>Basic syntax of unity script (8) - collaborative program and destruction method
Basic syntax of unity script (8) - collaborative program and destruction method
2022-07-02 03:28:00 【ht_ game】
Collaborative process
Collaborative process , That is to say The main program Start while running Another logic processing to coordinate the execution of the current program . But it is different from multithreaded programs , All cooperative programs are run in the main program , It is also a single threaded program . stay Unity Through StartCoroutine Method to start collaboration .
StartCoroutine Method is MonoBehavior A method in class , That is, the method must be in MonoBehavior Or inherit from MonoBehavior Call in class .StartCoroutine Method can return a value of IEnumerator As a parameter
void Start()
{
StartCoroutine(doThing1());// Turn on doThing1 Collaborative process
}
IEnumerator doThing1()// Statement doThing Method
{
yield return StartCoroutine(doThing2());// Turn on doThing2 Collaborative process
}
IEnumerator doThing2()
{
yield return new WaitForSeconds(2);// Cooperative program sleep 2s
}
Methods related to destruction
In the process of game development , I often meet people 、 Components 、 Resources, etc. lose their function after use , If you let it go , At least, it will affect the operation efficiency of the project , More importantly, it may affect the normal operation of the project . therefore , There must be a way to manage 、 Delete these useless resources .
| function | function |
|---|---|
| Object.Destroy | Delete game objects 、 Component or resource |
| NetWork.Destroy | Destroy network objects |
| MonoBehavior.OnDestroy | Called when the script is destroyed |
Object.Destroy Method
Object.Destroy Method can destroy the object immediately , You can also set the time to destroy . If the deleted object is a component , Then the component will be removed .
public GameObject obj;
void Start()
{
Destroy(obj.GetComponent<Rigidbody>());// Destroy rigid body components of game objects
Destroy(obj, 5);//5s Delete after obj The game object
}
NetWork.Destroy Method
NetWork.Destroy Method can destroy network objects , This object can be overloaded in two ways
public static void Destroy(NetworkViewID viewID)
public static void Destory(Gameobject gameobject)
1、 The system will delete all and the ViewID Related objects
2、 Destroy game objects on the network
Network.Destory(GetComponent<NetworkView>().viewID)
Network.Destory(gameobject)
MonoBehaviour.OnDestroy Method
MonoBehaviour.OnDestroy The method is MonoBehaviour Destroy callback method in
边栏推荐
- Named block Verilog
- Continuous assignment of Verilog procedure
- [JS reverse series] analysis of a customs publicity platform
- 跟着CTF-wiki学pwn——ret2shellcode
- spark调优
- 《MATLAB 神经网络43个案例分析》:第41章 定制神经网络的实现——神经网络的个性化建模与仿真
- Global and Chinese markets for hand hygiene monitoring systems 2022-2028: Research Report on technology, participants, trends, market size and share
- Verilog 避免 Latch
- 数据库文件逻辑结构形式指的是什么
- 32, 64, 128 bit system
猜你喜欢

Which of PMP and software has the highest gold content?

Verilog avoid latch

Yan Rong looks at how to formulate a multi cloud strategy in the era of hybrid cloud

Analyse de 43 cas de réseaux neuronaux MATLAB: Chapitre 42 opérations parallèles et réseaux neuronaux - - opérations parallèles de réseaux neuronaux basées sur CPU / GPU

Exchange rate query interface

Comment élaborer une stratégie nuageuse à l'ère des nuages mixtes

跟着CTF-wiki学pwn——ret2shellcode

JS <2>

表单自定义校验规则

QT environment generates dump to solve abnormal crash
随机推荐
Retrofit's callback hell is really vulnerable in kotlin synergy mode
Kotlin basic learning 16
Common means of modeling: aggregation
GSE104154_scRNA-seq_fibrotic MC_bleomycin/normalized AM3
Verilog 过程赋值 区别 详解
Review materials of project management PMP high frequency examination sites (8-1)
Global and Chinese market of bone adhesives 2022-2028: Research Report on technology, participants, trends, market size and share
verilog REG 寄存器、向量、整数、实数、时间寄存器
< job search> process and signal
Gradle notes
Apple added the first iPad with lightning interface to the list of retro products
On redis (II) -- cluster version
Verilog parallel block implementation
C shallow copy and deep copy
Unity脚本的基础语法(6)-特定文件夹
Kotlin基础学习 14
《MATLAB 神经网络43个案例分析》:第42章 并行运算与神经网络——基于CPU/GPU的并行神经网络运算
uniapp 使用canvas 生成海报并保存到本地
Design details of SAP e-commerce cloud footernavigationcomponent
《MATLAB 神經網絡43個案例分析》:第42章 並行運算與神經網絡——基於CPU/GPU的並行神經網絡運算