using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using UnityEngine; using System.Collections; class PotionEffectsManager : ItemEffectsManager { public static new PotionEffectsManager Instance; public override void Awake() { if (Instance == null) { Instance = this; } else { Destroy(gameObject); } } public override void UseItemEffect(ItemSlot itemSlot, PanelTypeEnum originPanel) { // origin panel is passed for script to be able to recognize from which list to remove the object etc... DetectPotionType(itemSlot); // use other action binded to item 2 itemSlot.Item?.InvokeEffectAction(); // remove potion from a slot in specific panel... var panelUiManager = DetectOriginPanel(originPanel); panelUiManager.RemoveByPosition(itemSlot.Number); panelUiManager.UpdateList(); // refresh view } public void DetectPotionType(ItemSlot itemSlot) { var item = itemSlot.Item; // detect potion and use matched action if (item.name == "Full Health Potion") { HealthBigPotion(); } else if(item.name == "Medium Health Potion") { HealthMediumPotion(); } else if(item.name == "Small Health Potion") { HealthSmallPotion(); } else if(item.name == "Beer") { Drink(); } else if(item.name == "Crab Venom") { CrabPoison(); } else if(item.name == "Mushroom Venom") { MushroomPoison(); } } public void Drink() { PlayerPrefs.SetInt("drunk", 1); StartCoroutine(SoberUp()); } public IEnumerator SoberUp() { yield return new WaitForSecondsRealtime(6); PlayerPrefs.SetInt("drunk", 2); } // use below function in one above - depending on the condition public void HealthBigPotion() { var playerMaxHealth = PlayerPrefs.GetFloat("maxHealth"); var playerCurrentHealth = PlayerPrefs.GetFloat("health"); playerCurrentHealth = playerMaxHealth; PlayerPrefs.SetFloat("health", playerCurrentHealth); } public void HealthMediumPotion() { var playerMaxHealth = PlayerPrefs.GetFloat("maxHealth"); var playerCurrentHealth = PlayerPrefs.GetFloat("health"); if(playerCurrentHealth < playerMaxHealth / 2) { playerCurrentHealth = playerCurrentHealth + playerMaxHealth / 2; } else { playerCurrentHealth = playerMaxHealth; } PlayerPrefs.SetFloat("health", playerCurrentHealth); } public void HealthSmallPotion() { var playerMaxHealth = PlayerPrefs.GetFloat("maxHealth"); var playerCurrentHealth = PlayerPrefs.GetFloat("health"); if(playerCurrentHealth < playerMaxHealth*3/4) { playerCurrentHealth = playerCurrentHealth + playerMaxHealth / 4; } else { playerCurrentHealth = playerMaxHealth; } PlayerPrefs.SetFloat("health", playerCurrentHealth); } public void CrabPoison() { var playerMaxHealth = PlayerPrefs.GetFloat("maxHealth"); var playerCurrentHealth = PlayerPrefs.GetFloat("health"); playerCurrentHealth = playerMaxHealth * 3/4; PlayerPrefs.SetFloat("health", playerCurrentHealth); } public void MushroomPoison() { var playerMaxHealth = PlayerPrefs.GetFloat("maxHealth"); var playerCurrentHealth = PlayerPrefs.GetFloat("health"); playerCurrentHealth = playerMaxHealth * 1 / 2; PlayerPrefs.SetFloat("health", playerCurrentHealth); } // Add and invoke your own functions }