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

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); 
    } 
主站蜘蛛池模板: 山阴县| 长顺县| 弥勒县| 万盛区| 盐边县| 桂平市| 龙里县| 西盟| 大荔县| 蓬安县| 雷波县| 怀化市| 休宁县| 台安县| 甘泉县| 郸城县| 方正县| 伊宁市| 资阳市| 华亭县| 临朐县| 涿鹿县| 桃源县| 托克托县| 崇礼县| 乐昌市| 静安区| 岳阳市| 贺州市| 台北县| 南康市| 安仁县| 阳东县| 盐源县| 三亚市| 东兴市| 灵台县| 丽江市| 那曲县| 威信县| 宣恩县|