官术网_书友最值得收藏!

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); 
    } 
主站蜘蛛池模板: 高淳县| 雷波县| 仁化县| 抚远县| 乌鲁木齐市| 玛纳斯县| 南召县| 静宁县| 武强县| 北辰区| 封丘县| 始兴县| 秀山| 利津县| 西宁市| 义乌市| 锦屏县| 老河口市| 南皮县| 陈巴尔虎旗| 徐水县| 宿州市| 保靖县| 蓬莱市| 辰溪县| 安西县| 凌云县| 泰和县| 丹东市| 樟树市| 漯河市| 高唐县| 黄骅市| 镇原县| 镇沅| 大丰市| 长乐市| 西华县| 湄潭县| 邯郸市| 太仓市|