Tying a Slider to a Dialogue System Variable
Tying a Slider to a Dialogue System Variable
I'm trying to use the Dialogue system to make some turn-based combat, and I currently have the player health as a variable in the dialogue system. How do I make a health slider that adjusts with the health whenever the player takes damages?
Re: Tying a Slider to a Dialogue System Variable
Hi Alex,
Write a C# method, and register it as a Lua function. Something like:
Then use SetHealth() to change the health variable. Instead of setting the Script field to this:
use this:
Write a C# method, and register it as a Lua function. Something like:
Code: Select all
using PixelCrushers.DialogueSystem;
public UnityEngine.UI.Slider healthBar;
...
void Awake()
{
Lua.RegisterFunction("SetHealth", this, SymbolExtensions.GetMethodInfo(() => SetHealth((double)0)));
}
public void SetHealth(double health)
{
DialogueLua.SetVariable("PlayerHealth", health);
healthBar.value = health;
}
Code: Select all
Variable["Health"] = Variable["Health"] + 10;
Code: Select all
SetHealth(Variable["Health"] + 10)
Re: Tying a Slider to a Dialogue System Variable
What should I attach the script to? The Dialogue Manager?
Re: Tying a Slider to a Dialogue System Variable
Hi,
Yes, that's a good choice.
Yes, that's a good choice.