- 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); }
推薦閱讀
- 物聯(lián)網(wǎng)短距離無線通信技術(shù)應(yīng)用與開發(fā)
- Django 2 by Example
- Web Application Development with R Using Shiny
- Hands-On Full Stack Development with Spring Boot 2 and React(Second Edition)
- 局域網(wǎng)組建、管理與維護項目教程(Windows Server 2003)
- Building RESTful Web Services with Spring 5(Second Edition)
- 電力物聯(lián)網(wǎng)工程技術(shù)原理與應(yīng)用
- CCNP TSHOOT(642-832)認證考試指南
- 2小時讀懂物聯(lián)網(wǎng)
- 面向5G-Advanced的關(guān)鍵技術(shù)
- 4G小基站系統(tǒng)原理、組網(wǎng)及應(yīng)用
- VMware NSX網(wǎng)絡(luò)虛擬化入門
- 6G無線網(wǎng)絡(luò)空口關(guān)鍵技術(shù)
- 互聯(lián)網(wǎng)+思維與創(chuàng)新:通往未來的+號
- Getting Started with Memcached