Skip to content

Instantly share code, notes, and snippets.

@Dssdiego
Last active April 28, 2020 08:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Dssdiego/36f331c0460a5187f5ed7a74418d1ed3 to your computer and use it in GitHub Desktop.
Save Dssdiego/36f331c0460a5187f5ed7a74418d1ed3 to your computer and use it in GitHub Desktop.
Unity Int Variable according to [Best Practices](https://unity.com/how-to/architect-game-code-scriptable-objects)
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;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment