示例#1
0
    void OnTriggerEnter(Collider other)
    {
        if (other.tag == "Bullet")
        {
            return;
        }

        if (other.tag == "Obstacle" || other.tag == "Enemy")
        {
            // Lose health only if we're not invulnerable
            if (!IsInvulnerable && other.GetComponent <Attack>() != null)
            {
                HealthSystem.Damage(other.GetComponent <Attack>().Damage);
                SendPlayerHurtMessages();
            }
        }

        // Remove Player when we have no Health
        if (HealthSystem.GetHealth() == 0)
        {
            if (Explosion != null)
            {
                Instantiate(Explosion, transform.position, transform.rotation);
            }
            GameController.RemovePlayer(gameObject);
            Destroy(gameObject);
        }

        // Some collision explosion and destroying enemies with no health on collision
        if (other.GetComponent <Enemy_G>() != null)
        {
            if (other.GetComponent <CollisionExplosion>() != null)
            {
                Instantiate(other.GetComponent <CollisionExplosion>().Explosion, other.transform.position, other.transform.rotation);
            }
            if (other.GetComponent <Enemy_G>().GetHealthSystem().GetHealth() == 0)
            {
                Destroy(other.gameObject);
            }
        }
    }