Adding Health Potions to RPG series

Updated 4 hours ago in [A] Brackeys Courses
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
1 5 days ago

Hello All,

So, I recently went through the RPG series, I really liked it by the way. I am definitely expanding upon it and I added a Health potion item. To do this, I basically created a Potion script that inherited from the Item class and I am overriding the Use method. I figured out a way to get everything to work but, I don’t feel like it is necessarily the best way to go about the process. Here is basically what I came up with:

Potion class Use method:

    public override void Use()
   {
       base.Use();
 
    CharacterStats myStats = PlayerManager.instance.player.GetComponent(CharacterStats);    

 

   if (myStats != null)
        {
            myStats.Heal(healAmount);
       }
        RemoveFromInventory();
    }
 
(The Heal method basically just adds the healAmount to currentHealth)
Because the currentHealth variable has a private setter on the CharacterStats script, I can’t really think of another way to do this. Is this a good way to go about doing this or might there be a better way to do this? 

Also, I would add code tags but, I do not see them on the Text editor bar where I read they would be… 

  • Liked by
Reply
0 4 hours ago

Bump

 

  • Liked by
Reply
Cancel