当前位置:网站首页>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
边栏推荐
- h5中的页面显示隐藏执行事件
- PY3, PIP appears when installing the library, warning: ignoring invalid distribution -ip
- What is hybrid web containers for SAP ui5
- Pycharm2021 delete the package warehouse list you added
- venn圖取交集
- The page in H5 shows hidden execution events
- aaaaaaaaaaaaa
- Comment élaborer une stratégie nuageuse à l'ère des nuages mixtes
- 跟着CTF-wiki学pwn——ret2shellcode
- 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
猜你喜欢
Knowing things by learning | self supervised learning helps improve the effect of content risk control
《MATLAB 神經網絡43個案例分析》:第42章 並行運算與神經網絡——基於CPU/GPU的並行神經網絡運算
On redis (II) -- cluster version
Comment élaborer une stratégie nuageuse à l'ère des nuages mixtes
"Analysis of 43 cases of MATLAB neural network": Chapter 41 implementation of customized neural network -- personalized modeling and Simulation of neural network
数据传输中的成帧
[C Advanced] brother Peng takes you to play with strings and memory functions
汇率的查询接口
Oracle的md5
[untitled] basic operation of raspberry pie (2)
随机推荐
焱融看 | 混合云时代下,如何制定多云策略
Yan Rong looks at how to formulate a multi cloud strategy in the era of hybrid cloud
Gradle notes
[HCIA continuous update] working principle of OSPF Protocol
32, 64, 128 bit system
Download and use of the super perfect screenshot tool snipaste
数据传输中的成帧
PHP array processing
C#联合halcon脱离halcon环境以及各种报错解决经历
Global and Chinese markets for welding equipment and consumables 2022-2028: Research Report on technology, participants, trends, market size and share
Verilog 时序控制
Docker安装canal、mysql进行简单测试与实现redis和mysql缓存一致性
Intersection of Venn graph
Kotlin basic learning 14
《MATLAB 神经网络43个案例分析》:第41章 定制神经网络的实现——神经网络的个性化建模与仿真
[untitled] basic operation of raspberry pie (2)
表单自定义校验规则
MySQL advanced (Advanced) SQL statement (II)
Oracle的md5
Load different fonts in QML