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();
}