当前位置:网站首页>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
边栏推荐
- FFMpeg AVFrame 的概念.
- Global and Chinese markets for ultrasonic probe disinfection systems 2022-2028: Research Report on technology, participants, trends, market size and share
- Global and Chinese markets for infant care equipment, 2022-2028: Research Report on technology, participants, trends, market size and share
- 微信小程序中 在xwml 中使用外部引入的 js进行判断计算
- Kotlin basic learning 14
- Uniapp uses canvas to generate posters and save them locally
- spark调优
- [punch in] flip the string (simple)
- h5中的页面显示隐藏执行事件
- ORA-01547、ORA-01194、ORA-01110
猜你喜欢
SAML2.0 笔记(一)
【DesignMode】建造者模式(Builder model)
SAML2.0 notes (I)
verilog 并行块实现
West digital decided to raise the price of flash memory products immediately after the factory was polluted by materials
JS introduction < 1 >
Detailed explanation of ThreadLocal
命名块 verilog
高性能 低功耗Cortex-A53核心板 | i.MX8M Mini
Docker安装canal、mysql进行简单测试与实现redis和mysql缓存一致性
随机推荐
One of the future trends of SAP ui5: embrace typescript
Design details of SAP e-commerce cloud footernavigationcomponent
venn图取交集
Load different fonts in QML
[C Advanced] brother Peng takes you to play with strings and memory functions
How to establish its own NFT market platform in 2022
一天上手Aurora 8B/10B IP核(5)----从Framing接口的官方例程学起
Kotlin basic learning 13
Verilog 线型wire 种类
aaaaaaaaaaaaa
Docker安装canal、mysql进行简单测试与实现redis和mysql缓存一致性
C # joint halcon out of halcon Environment and various Error Reporting and Resolution Experiences
Continuous assignment of Verilog procedure
What is hybrid web containers for SAP ui5
C#联合halcon脱离halcon环境以及各种报错解决经历
PHP array processing
Calculation of page table size of level 2, level 3 and level 4 in protection mode (4k=4*2^10)
Use blocking or non blocking for streamline
In depth interpretation of pytest official documents (26) customized pytest assertion error information
[database]jdbc