// If pickup hits player, add health (max. 100), destroy health pickup private void OnTriggerEnter2D(Collider2D other) { // If player has at most 90 health, increase it by healthUp if (other.gameObject.tag == "Player" && stats.getHealth() <= 90) { float playerHealth = stats.getHealth(); // Get player health stats.setHealth(playerHealth + healthUp); // Increase health sfx.PlaySound(sfx.healthPickup); // Play pickup sound ui.SetHealthBGColor(pickupColor); // Color health BG red Destroy(this.gameObject); // Destroy pickup // If player has 90 or more health, it becomes 100 on pickup } else if (other.gameObject.tag == "Player") { stats.setHealth(healthMax); // Max health sfx.PlaySound(sfx.healthPickup); // Play pickup sound ui.SetHealthBGColor(pickupColor); // Color health BG red Destroy(this.gameObject); // Destroy pickup } }
// Damage player function public void damagePlayer(float damage) { playerHealthFloat -= damage; ui.SetHealthBGColor(hurtColor); sfx.PlaySound(sfx.maleScream6); }