Dssdiego
4/23/2020 - 7:10 PM

IntVariable

Unity Int Variable according to Best Practices

using UnityEngine;
using UnityEngine.Events;

[CreateAssetMenu(menuName = "Variable/Int")]
public class IntVariable : ScriptableObject 
{
#if UNITY_EDITOR
    [Multiline]
    public string description;
#endif

    public int runtimeValue;
    public int initialValue;
        
    public UnityAction<int> OnChanged;

    public void Add(int val)
    {
        runtimeValue += val;
        OnChanged?.Invoke(runtimeValue);
    }

    public void Reset()
    {
        runtimeValue = initialValue;
    }
}