I'm developing a simple NPC controller that the player can talk with.
At the moment a
NPCController script on the NPC gameobject manages several "high level" feature of the NPC such as intelligence.
Every time the player talks with the NPC, the latter will respond with "Bzz", "Hello" or "Heya" depending on his intelligence level.
The talking part is implemented in a
TalkController script. I did this way in order to have multiple behaviours depending on the player/npc interaction without creating a giant
NPCController class. Plus some NPC may not speak at all (in this case I'd simply remove the
I have a small dilemma on how to change the NPC response in
TalkController based on the intelligence level in
I could use Events:
// NPCController.cs public delegate void OnIntelligenceLevelHandler(int level); public static event OnIntelligenceLevelHandler OnIntelligenceLevelChanged; // When intelligence increases OnIntelligenceLevelChanged(2);
// TalkController.cs // Store _intelligence = 1; // Subscribe to OnIntelligenceLevelChanged // Upgrade _intelligence when the event fires // Switch word on _intelligence when talking
I could use a direct reference:
// TalkController.cs // Store _npccontroller = GetComponent<NPCController>(); // Switch word on _npccontroller.Intelligence when talking
What would be the best approach?