Skill Tree
  • Skill Tree Documentation
  • Legacy Product
  • đŸ•šī¸Quick Start
    • Installation
    • Default Prefabs
    • Start Editing
    • Making it Work
  • 🎮Demo Scene
    • Endless Death
  • âš™ī¸Systems
    • Skill Tree
      • Editor Window
        • Skill Trees (Skill Graphs)
        • Skills (Skill Nodes)
          • Skill Stats Editor
          • Text Tags
        • Connections
      • Skill Tree Settings
      • Components
        • Skill Tree Initializer
        • Default Components
          • Confirmation Prompt
          • Default Input Handler
          • Skill Tree Window
          • Skill Details
          • Skill Menu
          • Skill Bar & Windup UI
        • Skill Interpreter
      • Customizations
        • UI Customizations
          • Custom Skill Menu
          • Custom Skill Details
        • Custom Objects
      • Scripting
        • Initialization
        • Player Level & Skill Points
        • Skill Graphs
        • Skill Nodes
        • Using Skills
        • Saving & Loading Graphs
        • Default Skill Tree Window
        • Events
    • Stats
      • Stats Editor
      • Components
        • Unit Stats Provider
      • Creating & Providing Stats
      • Scripting
        • Stat Groups & Identities
        • Stats
        • Unit Stats Provider
          • Events
        • Saving & Loading Stats
  • đŸ› ī¸Support
    • Getting Help
  • 📚Changelogs
    • Latest Releases
  • ⭐Rate Me?
Powered by GitBook
On this page
  • Usage Example
  • Script Example
  1. Systems
  2. Stats
  3. Scripting
  4. Unit Stats Provider

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...
    }
}
PreviousUnit Stats ProviderNextSaving & Loading Stats

Last updated 5 months ago

âš™ī¸