using System.Collections; using System.Collections.Generic; using UnityEngine; using Assets.Scripts.CharacterScripts; public class HealingController : MonoBehaviour{ public int healingAmountByPercent; // Amount the item heals the player by public PlayerController player; // Reference to the player void Start(){ player = GameObject.FindGameObjectWithTag("Player").GetComponent(); // Prime the item for player contact } private void OnCollisionEnter2D(Collision2D other) { // If the item makes contact with the player or the player's weapon (just to be extra sure) if (other.gameObject.CompareTag("Player") || other.gameObject.CompareTag("PlayerWeapon")){ // Increase the player's current health by the healing amount and set the health bar accordingly if (healingAmountByPercent == 20){ player.currentHealth += Mathf.CeilToInt(player.maxHealth * .2f); } else if (healingAmountByPercent == 50){ player.currentHealth += Mathf.CeilToInt(player.maxHealth * .5f); } // Make sure the current health doesn't exceed max health if (player.currentHealth >= player.maxHealth){ player.currentHealth = player.maxHealth; } player.healthBar.SetHealth(player.currentHealth); // Destroy the healing Destroy(gameObject); } else if (!other.gameObject.CompareTag("Player")){ // Ignore any other contact that isn't the player Physics2D.IgnoreCollision(GetComponent(), other.collider, true); } } }