Trying to Add HealthPack, Not Sure How to Actually Heal Unit

So long story short, I’ve completed the Turn-based Strategy Game tutorial and I’m looking to expand the game a bit. I want to add a health potion/pack to allow players to heal a unit and continue fighting. I’ve gotten most of the way there on my own. I’ve set up a “HealthPack” script that extends the IInteractble interface, much like the door or InteractSphere. Everything works, and I’ve also got the LevelGrid updating before the object is destroyed so it’s properly removed from the scene.

Now, my last hurdle is getting the HealthPack to talk to the Unit who selected it, and heal them. I have a function in the “HealthSystem” script to restore their health to the max, but I’m unsure of how to tell the function to run. I need to create a connection between the instance of the HealthPack that was selected, and the Unit who selected it. Any tips or advice?

You can get the selected Unit from the UnitActionSystem and then get that unit’s health component

var selectedUnit = UnitActionSystem.Instance.GetSelectedUnit();
var unitHealth = selectedUnit.GetComponent<HealthSystem>();
unitHealth.Heal();

Worked like a charm! This will actually help me solve some other problems I was having with making more interactive objects, so many thanks for getting me over the hump!

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms