Example #1
0
    void OnTriggerEnter2D(Collider2D col)
    {
        if (col.gameObject.name == "player" && !activated)
        {
            activated = true;             // added this to prevent being able to get the power up twice while the sound is playing.
            Debug.Log("We have picked up a " + Enum.GetName(typeof(PowerUpTypes), myPower) + " powerup!");

            if (myPower == 0)            // small heal
            {
                Debug.Log("HP: " + player.getHpCurrent() + "/" + player.getHpMax());
                player.changeHpCurrent(3);                  // just test numbers
                Debug.Log("HP: " + player.getHpCurrent() + "/" + player.getHpMax());
            }
            if (myPower == 1)            // full heal
            {
                Debug.Log("HP: " + player.getHpCurrent() + "/" + player.getHpMax());
                player.changeHpCurrent(999);
                Debug.Log("HP: " + player.getHpCurrent() + "/" + player.getHpMax());
            }
            if (myPower == 2)
            {
                player.addAmmo(5);
            }


            soundEffect.PlayOneShot(aClip);
            GetComponent <SpriteRenderer>().enabled = false; // hide the object in the scene so it looks destroyed
            Destroy(gameObject, aClip.length);               // destroy when sound is done playing
        }
    }