Last active
April 28, 2020 08:46
-
-
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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