Exemplo n.º 1
0
 private void OnTriggerEnter2D(Collider2D collision)
 {
     if (collision.transform.tag == "enemybullet" || collision.transform.tag == "bossbullet")//与玩家的子弹发生碰撞
     {
         float damage = collision.GetComponent <EnemyBullet>().powerEnemyBullet + EnemyBullet.addPowerEnemyBullet;
         this.currentHealth -= damage;      //生命值-敌方子弹伤害
         Game.ReduceHealth(damage, health); //改变血条
         Destroy(collision.gameObject);     //碰撞后子弹消失
     }
     if (collision.transform.tag == "healthbox")
     {
         if (this.currentHealth + collision.GetComponent <HealthBox>().health <= health)
         {
             this.currentHealth += collision.GetComponent <HealthBox>().health;//生命值+盒子携带的生命值
             //lifeBar.fillAmount += collision.GetComponent<HealthBox>().health / health;//改变血条
             Game.AddHealth(collision.GetComponent <HealthBox>().health, health);
             Destroy(collision.gameObject);//碰撞后盒子消失
         }
         else if (this.currentHealth + collision.GetComponent <HealthBox>().health >= health)
         {
             this.currentHealth = health;
             //lifeBar.fillAmount = 1f;
             Game.FillHealth();
             Destroy(collision.gameObject);//碰撞后盒子消失
         }
     }
     if (currentHealth <= 0)
     {
         Destroy(gameObject);                                        //飞机爆炸
         StartGame.selfPlane.isAlive = false;
         Instantiate(boom, transform.position, Quaternion.identity); //显示爆炸动画
     }
 }