Creating an Event Through Code
Creating an Event Through Code
Emerald AI's Unity Events are located on the EmeraldEvents script. To access these, you will need a reference to the EmeraldEvents script. This can be done using the code below. It is best to have a class level variable for EventsComponent so it can be accessed anywhere within your script.
You can add events programmatically using the following code format. These should be applied on Start.
For example, lets say you want to track each AI death and add it to a static variable so the player can track their kills. For this example, the kill count script name is KillCounterSystem and the static variable is an int called AmountOfKills.
All Events with Examples
OnDeathEvent
The OnDeathEvent is invoked when an AI is killed.
Example:
OnTakeDamageEvent
The OnTakeDamageEvent is invoked each time an AI is damaged.
Example:
OnDoDamageEvent
The OnDoDamageEvent is invoked each time an AI deals damage for both Melee and Ranged weapon types.
Example:
OnReachedDestinationEvent
The OnReachedDestinationEvent is invoked when an AI reaches their destination location (must be using the Destination Wander Type).
Example:
OnStartEvent
The OnStartEvent is invoked once within the AI's Start function.
Example:
OnEnabledEvent
The OnEnabledEvent is invoked when an AI is enabled after it has been deactivated.
Example:
OnPlayerDetectionEvent
The OnPlayerDetectionEvent is invoked when an AI detects a player object. Users can adjust the cooldown for how often this event is invoked within the Emerald AI editor.
Example:
OnAttackEvent
The OnAttackEvent is invoked when an AI triggers their attack animation.
Example:
OnFleeEvent
The OnFleeEvent is invoked when an AI begins to flee (This only happens with AI that have a Brave or Coward Confidence Level).
Example:
OnStartCombatEvent
The OnStartCombatEvent is invoked when an AI first enters combat and is reset when the battle is over.
Example:
OnEndCombatEvent
The OnEndCombatEvent is invoked when the AI ends combat and there are no detectable enemy targets nearby.
Example:
OnKillTargetEvent
The OnKillTargetEvent is invoked when an AI has killed their target. This event is called before an AI's target has been cleared so it can still be accessed if needed.
Example: