You would need to define a custom action in your behavior tree and a component on your player to hold the value. So assuming you have never done this before I’ll go from the top:
In the behavior tree editor add a custom action to your tree, right click, Create->Actions->Custom Action.
On the Custom Action select the drop down for Class and choose Create Custom Action.
Fill out a name and choose a language, and hit OK.
This creates an action in the folder AI/Actions
The action can do almost anything, but in your case it’s going to try to access some health component to see your current health. The component might look like this:
using UnityEngine;
public class HealthComponent : MonoBehaviour
{
[SerializeField]
private int _health = 10;
public int Health
{
get { return _health; }
set { _health = value; }
}
// Some code that modifies your health would be elsewhere, maybe in an update or function
}
And the action might look like this:
using RAIN.Action;
using UnityEngine;
[RAINAction]
public class CheckHealth : RAINAction
{
private HealthComponent _targetHealth = null;
public override void Start(RAIN.Core.AI ai)
{
base.Start(ai);
_targetHealth = null;
// This was detected and assigned to the Form Variable "target"
GameObject tTargetObject = ai.WorkingMemory.GetItem<GameObject>("target");
if (tTargetObject != null)
_targetHealth = tTargetObject.GetComponent<HealthComponent>();
}
public override ActionResult Execute(RAIN.Core.AI ai)
{
// Look at the component and return failure if it has no health
if (_targetHealth == null || _targetHealth.Health <= 0)
return ActionResult.FAILURE;
return ActionResult.SUCCESS;
}
}