- Unity Artificial Intelligence Programming
- Dr. Davide Aversa Aung Sithu Kyaw Clifford Peters
- 111字
- 2021-06-10 18:57:50
The Dead state
If the tank has reached the Dead state, we make it explode:
protected void UpdateDeadState() { //Show the dead animation with some physics effects if (!bDead) { bDead = true; Explode(); } }
Here's a small function that will give a nice explosion effect. We just apply an ExplosionForce function to our rigidbody component with some random directions, as shown in the following code:
protected void Explode() { float rndX = Random.Range(10.0f, 30.0f); float rndZ = Random.Range(10.0f, 30.0f); for (int i = 0; i < 3; i++) { rigidbody.AddExplosionForce(10000.0f, transform.position - new Vector3(rndX, 10.0f, rndZ), 40.0f, 10.0f); rigidbody.velocity = transform.TransformDirection( new Vector3(rndX, 20.0f, rndZ)); } Destroy(gameObject, 1.5f); }
推薦閱讀
- OpenLayers Cookbook
- 大話社交網絡
- 計算機網絡工程實用教程(第2版)
- 電力物聯網工程技術原理與應用
- 數字調制解調技術的MATLAB與FPGA實現:Altera/Verilog版(第2版)
- Master Apache JMeter:From Load Testing to DevOps
- Learning Storm
- 大型企業微服務架構實踐與運營
- 精通SEO:100%網站流量提升密碼
- Enterprise ApplicationDevelopment with Ext JSand Spring
- 智慧城市中的物聯網技術
- 計算機通信網絡安全
- 從物聯到萬聯:Node.js與樹莓派萬維物聯網構建實戰
- Architecting Data:Intensive Applications
- 通信系統實戰筆記:無處不在的信號處理