/// <summary> /// Raises the item click event. /// </summary> /// <param name="item">Item.</param> public void OnItemUse(GameObject item) { if (item != null) { // Heal on potion use DummyHealthPotion healthPotion = item.GetComponent <DummyHealthPotion>(); ClickItem clickItem = item.GetComponent <ClickItem>(); if (healthPotion != null) { if (GetHealth() < GetMaxHealth()) { // Add health if it is not full AddHealth(healthPotion.healAmount); if (audioSource != null && clickItem != null && clickItem.audioClip != null) { audioSource.PlayOneShot(clickItem.audioClip); } StackItem stackItem = item.GetComponent <StackItem>(); if (stackItem != null) { // Reduce potion's stack stackItem.ReduceStack(1); } } } } }
/// <summary> /// Raises the item click event. /// </summary> /// <param name="item">Item.</param> private void OnItemClick(GameObject item) { if (item != null) { // Heal on potion use DummyHealthPotion healthPotion = item.GetComponent <DummyHealthPotion>(); if (healthPotion != null) { if (GetHealth() < GetMaxHealth()) { AddHealth(healthPotion.healAmount); if (audioSource != null && healSound != null) { audioSource.PlayOneShot(healSound); } StackItem stackItem = item.GetComponent <StackItem>(); if (stackItem != null) { // Reduce potion's stack stackItem.ReduceStack(1); } } } } }
/// <summary> /// Raises the item click event. /// </summary> /// <param name="item">Item.</param> public void OnItemUse(GameObject item) { if (item != null) { // We can use potions only if vendor is inactive if (vendorStackGroup == null || vendorStackGroup.isActiveAndEnabled == false) { // Heal on potion use DummyHealthPotion healthPotion = item.GetComponent <DummyHealthPotion>(); ClickItem clickItem = item.GetComponent <ClickItem>(); if (healthPotion != null) { if (GetHealth() < GetMaxHealth()) { // Add health if it is not full AddHealth(healthPotion.healAmount); PlaySound(clickItem.audioClip); StackItem stackItem = item.GetComponent <StackItem>(); if (stackItem != null) { // Reduce potion's stack stackItem.ReduceStack(1); } } } } } }