Creating an Event Through Code
Creating an Event Through Code
EventsComponent = GetComponent<EmeraldEvents>();EventsComponent.TheEmeraldAIUnityEvent.AddListener(() => { YourFunctionToCall(); });...
void Start ()
{
//Create an OnDeathEvent by adding a listener and applying the CountDeath function.
//Even though this is assigned on start, the CountDeath function will be called when the AI dies.
EventsComponent.OnDeathEvent.AddListener(() => { CountDeath(); });
}
//The CountDeath function adds the AI's death to the static variable AmountOfKills for tracking kills.
void CountDeath ()
{
KillCounterSystem.AmountOfKills++;
}
...