Best practice to get GameObject of conversant whose conversation called a registered Lua function?
Posted: Wed Oct 13, 2021 7:49 pm
My situation is the following:
I have multiple enemies in the scene (GameObject + Monobehavior), who will start a conversation with the player on sight. Depending on the answers, I want the enemies to attack the player, which is basically done by calling a function of the enemy.
I tried doing this with the Lua RegisterFunction method in the Monobehavior of the enemies, but as the documentation already says, I cannot use RegisterFunction for MonoBehaviors which are placed multiple times in the scene, since now, the "attack player" function of some other enemy is called and not the enemy who the player had the conversation with.
So, basically, what I need is a function that I can call from the dialogue system that calls a C# function for that enemy which was the conversant of that dialogue. Ultimately, I would like to call something like:
or
but both are not really possible from Lua.
What might be possible is something like:
But can I get that GameObject? What is the best practice for that?
I have multiple enemies in the scene (GameObject + Monobehavior), who will start a conversation with the player on sight. Depending on the answers, I want the enemies to attack the player, which is basically done by calling a function of the enemy.
I tried doing this with the Lua RegisterFunction method in the Monobehavior of the enemies, but as the documentation already says, I cannot use RegisterFunction for MonoBehaviors which are placed multiple times in the scene, since now, the "attack player" function of some other enemy is called and not the enemy who the player had the conversation with.
So, basically, what I need is a function that I can call from the dialogue system that calls a C# function for that enemy which was the conversant of that dialogue. Ultimately, I would like to call something like:
Code: Select all
enemy.attackPlayer();
Code: Select all
TriggerEnemyAttacksPlayer(GameObject enemy);
What might be possible is something like:
Code: Select all
public void TriggerEnemyAttacksPlayer()
{
GameObject enemy = GetGameObjectOfConversantWhoseConversationCalledThisFunction();
enemy.attackPlayer();
}