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()); } else if (myPower == 1) // full heal { Debug.Log("HP: " + player.getHpCurrent() + "/" + player.getHpMax()); player.changeHpCurrent(999); Debug.Log("HP: " + player.getHpCurrent() + "/" + player.getHpMax()); } 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 } }
void FixedUpdate() { hpCurrent = player.getHpCurrent(); hpMax = player.getHpMax(); hpCurrentGUI.text = hpCurrent.ToString(); hpMaxGUI.text = hpMax.ToString(); hpBar.maxValue = hpMax; hpBar.value = hpCurrent; }