Page 1 of 1

Tying a Slider to a Dialogue System Variable

Posted: Fri Mar 06, 2020 7:48 pm
by AlexNerd
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

Posted: Fri Mar 06, 2020 9:38 pm
by Tony Li
Hi Alex,

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;
}
Then use SetHealth() to change the health variable. Instead of setting the Script field to this:

Code: Select all

Variable["Health"] = Variable["Health"] + 10;
use this:

Code: Select all

SetHealth(Variable["Health"] + 10)

Re: Tying a Slider to a Dialogue System Variable

Posted: Sun Mar 08, 2020 1:04 pm
by AlexNerd
What should I attach the script to? The Dialogue Manager?

Re: Tying a Slider to a Dialogue System Variable

Posted: Sun Mar 08, 2020 1:53 pm
by Tony Li
Hi,

Yes, that's a good choice.