I've read about some similar scenarios in the forums but nothing that quite matches what I'm trying to do, so I'm hoping you can help me (I'm also pretty new to coding so I may be overlooking something very simple here):
In my game, the player can control any one of three player characters at will. Which player character is currently being controlled is set by a custom PlayerSwitcher script. My goal is to add something to that script to set variables within the dialogue system, so that NPC dialogue can branch in different directions depending on which character the player is controlling.
At first I set a boolean for each player in the Dialogue System variables tab (isShael is the default and set to 'true'):
Example: If you're controlling "Nyla," the NPC uses one branch, if you're "Shael" they use the other branch depending on the bool being true or false. (All of this so far seems straightforward).
In my PlayerSwitcher script, I added using PixelCrushers.DialogueSystem, and started by trying SetVariable as follows for each character, referring directly to the name of the variable:
Code: Select all
DialogueLua.SetVariable("isNyla", true);
Code: Select all
using UnityEngine;
using PixelCrushers.DialogueSystem;
public class RegisterLua : MonoBehaviour
{
public bool isNyla;
public bool isShael;
public bool isDwen;
public bool PlayerIsNyla()
{
return isNyla;
}
public bool PlayerIsShael()
{
return isShael;
}
public bool PlayerIsDwen()
{
return isDwen;
}
void OnEnable()
{
Lua.RegisterFunction("PlayerIsNyla", this, SymbolExtensions.GetMethodInfo(() => PlayerIsNyla()));
Lua.RegisterFunction("PlayerIsShael", this, SymbolExtensions.GetMethodInfo(() => PlayerIsShael()));
Lua.RegisterFunction("PlayerIsDwen", this, SymbolExtensions.GetMethodInfo(() => PlayerIsDwen()));
}
void OnDisable()
{
Lua.UnregisterFunction("PlayerIsNyla");
Lua.UnregisterFunction("PlayerIsShael");
Lua.UnregisterFunction("PlayerIsDwen");
}
}
Code: Select all
DialogueLua.SetVariable("PlayerIsNyla", true);
...and updated the conditions in the dialogue tree to use Custom.
The result was the same, the boolean isn't changing when SetVariable is triggered in the PlayerSwitcher script, and the NPC gives no dialogue. So I'm obviously missing something but I'm not sure where. It's also possible there's an easier/better way to set variables from outside scripts that I'm overlooking.
Any help would be appreciated. Thanks very much!