Registered function doesn't work
Posted: Sun Mar 01, 2020 2:10 pm
Hi
I have registered a C# method via RegisterFunction() and I am now trying to run it during a dialogue.
The method controls an image panel that should show different images during dialogues.
The method is on my GameManager script/object and is also registered from that script.
The method works fine when I just run it from Start() in the GameManager script, but nothing happens when I use it in dialogues. The image does not get added to the panel.
I have a feeling I am missing something simple here.
Maybe I have misunderstood what a registered function can be used for?
Here is my method in GameManager:
Here is my registration code in GameManager:
Here is the LUA code in the script field of the node:
I have registered a C# method via RegisterFunction() and I am now trying to run it during a dialogue.
The method controls an image panel that should show different images during dialogues.
The method is on my GameManager script/object and is also registered from that script.
The method works fine when I just run it from Start() in the GameManager script, but nothing happens when I use it in dialogues. The image does not get added to the panel.
I have a feeling I am missing something simple here.
Maybe I have misunderstood what a registered function can be used for?
Here is my method in GameManager:
Code: Select all
public void SetDialogueImage(string imageName)
{
var newSprite = dialogueSprites.Find(x => x.name == imageName);
dialogueImage.sprite = newSprite;
dialogueImage.gameObject.SetActive(true);
}
Code: Select all
void OnEnable()
{
Lua.RegisterFunction("SetDialogueImage", this, typeof(MyLuaFunctions).GetMethod("SetDialogueImage"));
Lua.RegisterFunction("ClearDialogueImage", this, typeof(MyLuaFunctions).GetMethod("ClearDialogueImage"));
}
void OnDisable()
{
Lua.UnregisterFunction("SetDialogueImage");
Lua.UnregisterFunction("ClearDialogueImage");
}
Code: Select all
SetDialogueImage("Bible_Open_512")