Hi there,
I am not sure if I am still ok to reply here. I have been trying to implement this so that the health ability doesn’t get used unless I need it. But unfortunately I must be doing something wrong as I can use the health ability anytime regardless if I am at full health or not. I would ideally like to use the health ability only when im losing health.
I have altered my code to showcase this tutorial. I dont have any errors. When I add the filter strategy to the health potion ability it doesnt work if the no targets is false. If its true it “works” but still i can use it anytime. I was wondering if I could get some help please?
Appreciate your time and help.
I managed to fix it I think. I applied these changes to your suggested IsInJuredFilter.cs and took the bool off for this no target required for the healthPotion. This seems to have fixed the issue for this particular case. Thank you for the tutorial however. I wouldn’t have been able to attempt this without your help above. Thank you.
namespace RPG.Abilities.Filters
{
[CreateAssetMenu(fileName = "Is Injured Filter", menuName = "Abilities/Filters/Is Injured Filter", order = 0)]
public class IsInjuredFilter : FilterStrategy
{
public override IEnumerable<GameObject> Filter(IEnumerable<GameObject> objectsToFilter)
{
foreach (GameObject gameObject in objectsToFilter)
{
if (gameObject.TryGetComponent(out Health health) && health.GetHeatlh()< health.GetMaxHealth())
{
yield return gameObject;
}
}
}
}
}