Events
Working with stat events.
Each Unit Stats Provider has its own events that you can use to make something happen when a stat is changed. Each event accepts an Stat
parameter.
Property
Description
onStatChanged
Called whenever a stat's current value is changed.
onStatReachedMin
Called whenever a stat's current value reaches its min value.
onStatReachedMax
Called whenever a stat's current value reaches its max value.
onStatLevelChanged
Called whenever a stat's level is changed.
Usage Example
Let's say you have a stat called HP. If you want something to happen when the HP reaches 0, you can use the onStatReachedMin
event.
Script Example
In this example, we're calling a custom function called Death
that handles player death when the HP stat reaches 0.
Adding the Listener
// Get the UnitStatsProvider component
var statsProvider = GetComponent<UnitStatsProvider>();
// Add a listener
statsProvider.onStatReachedMin.AddListener(Death);
Custom Function
public void Death(Stat stat)
{
// Check if it's the HP stat
if (stat.NameMatches("HP"))
{
// Your death code here...
}
}
Last updated