示例#1
0
    void OnCollisionEnter2D(Collision2D collision)
    {
        PlayerScript hero = collision.gameObject.GetComponent <PlayerScript>();

        if (hero != null)
        {
            switch (type)
            {
            case "hitPoints":
                HealthScript life = hero.gameObject.GetComponent <HealthScript>();
                life.Restore(add);
                Destroy(gameObject);
                // updating the Hero's HealthBar
                Canvas.FindObjectOfType <Slider>().value = life.hp;
                break;

            // Immunity power-up
            case "immunity":
                HealthScript immunity = hero.gameObject.GetComponent <HealthScript>();
                immunity.GetImmunity();
                Destroy(gameObject);
                break;
            }
        }
        else
        {
            Physics2D.IgnoreCollision(collision.gameObject.GetComponent <Collider2D>(), gameObject.GetComponent <Collider2D>());
        }
    }