Skip to content

Instantly share code, notes, and snippets.

@noahjames404
Created April 4, 2025 14:41
Show Gist options
  • Select an option

  • Save noahjames404/95729779f047bdde2652ce81fb4d7f8f to your computer and use it in GitHub Desktop.

Select an option

Save noahjames404/95729779f047bdde2652ce81fb4d7f8f to your computer and use it in GitHub Desktop.
Unity stat/attribute
using UnityEngine;
namespace kokomeron
{
[System.Serializable]
public class Stat
{
[SerializeField]
private float baseValue;
[SerializeField]
private float addons;
[SerializeField]
private float multiplier = 1;
public float BaseValue {
get => baseValue;
set
{
baseValue = value;
onStatUpdate?.Invoke(getValue());
}
}
public float Addons {
get => addons;
set
{
addons = value;
onStatUpdate?.Invoke(getValue());
}
}
public float Multiplier {
get => multiplier;
set
{
multiplier = value;
onStatUpdate?.Invoke(getValue());
}
}
public delegate void OnStatUpdate(float value);
public event OnStatUpdate onStatUpdate;
public float getValue()
{
return BaseValue * Multiplier + Addons;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment