I have a dialogue system number variable called "Money" that I want to display on my UI, however it doesn't update according to what's entered in the inspector.
using PixelCrushers.DialogueSystem;
public class Money : MonoBehaviour
{
public int moneyAmount;
public TextMeshProUGUI moneyDisplay;
void Update()
{
moneyDisplay.SetText(moneyAmount.ToString());
UpdateMoneyVar();
}
public void UpdateMoneyVar()
{
int moneyAmount = DialogueLua.GetVariable("Money").asInt;
}
I have registered 'UpdateMoneyVar()' with Lua in case that helps.
I see you also have a C# variable named moneyAmount. I recommend having only one variable to track money -- either your C# variable moneyAmount, or your Dialogue System Number variable Money.
If you use the DS variable, then in C# use DialogueLua.GetVariable() and SetVariable() to access it. Example:
Side note: Setting TextMeshProUGUI text in Update() is fine for an initial "get it working" pass. But I recommend changing it slightly in the future. When you set TextMeshProUGUI text, it rebuilds the entire mesh that visually represents the text. This is a somewhat heavy process that you don't need to do every frame. Instead, you can do it only when the Money variable changes. See Monitor Variable Changes.
int money = DialogueLua.GetVariable("Money").asInt;
DialogueLua.SetVariable("Money", money + 1);
DialogueManager.SendUpdateTracker(); // Add this line if you need to update the quest tracker HUD.