Event responders enable you to respond to c# events thrown by Components, and are typically used for things like particle effects and animations. Almost all components in Platformer Pro raise events so you can easily attach effects (or other behaviour) to these components.
Tip: You can also use EventResponders to listen and respond to events thrown by third-party scripts.
Quick Start - Responding to Damage
These steps assumes you have a character with a CharacterHealth component already set up in a scene. Make sure your character has more than 1 health.
1. Create a new empty GameObject as a child of your Character.
2. Rename this new GameObject to 'DamageEvent'.
3. Create a particle system and drag it so it as a child of the DamageEvent GameObject
4. Set up your Particle system: set Loop and Play on Awake to false. Change the duration and Start Lifetime to 1.
(Make sure you can see your particle system ... the default particle system will render behind sprites, so you may want to change the material or shader).
5. Add an EventResponder component to the DamageEvent GameObject.
6. Drag your Character GameObject in to the Sender field of the EventResponder.
7. Select CharacterHealth as the EventResponder
8. Set Damaged as the event and leave the DamageType set to NONE.
9. Click the Add Action button.
10. Choose PLAY_PARTICLES form the Action drop down list.
11. Drop your particle system from above in to the Particle System field.
Press play and cause your player some damage. The particle system will be played.
See Available Events for a list of available events.
Some events allow a filter to be assigned which can be used to only respond to the event if the conditions are met.
Damage Type - If you use damage type on your damage then you can set up different events based on the damage type. For example you could play fire particles when the damage type is FIRE, or ice particles when the damage type is COLD.
AnimationState - Filter the events by animation state to play particles based on the characters current animation.
ButtonEventArgs - Sent by touch buttons you can filter the response based on the state (DOWN, HELD, UP).
There are many action types available:
DEBUG_LOG - Logs a message to the console. Useful for testing.
SEND_MESSSAGE - Sends a user defined message to a Component. Use to invoke your own scripts.
ACTIVATE_GAMEOBJECT - Activates the given game object.
DEACTIVATE_GAMEOBJECT - Deactivates the given game object.
ENABLE_BEHAVIOUR - Enables the given behaviour.
DISABLE_BEHAVIOUR - Disables the given behaviour.
OVERRIDE_ANIMATON - Sets an animation override on the selected character.
CLEAR_ANIMATION_OVERRIDE - Clears all overrides on the selected character.
PLAY_PARTICLES - Plays a ParticleSystem.
PAUSE_PARTICLES - Pauses a ParticleSystem.
SWITCH_SPRITE - Switches the sprite on a sprite renderer.
PLAY_SFX - Plays a sound effect (only for audio set up using SFX system).
PLAY_SONG - Plays a song (only for audio set up using SONG system).
STOP_SONG - Stops a song (only for audio set up using SONG system).
MAKE_INVULNERABLE - Makes character invulnerable for period of time.
MAKE_VULNERABLE - Makes character vulnerable again.
LEVEL_COMPLETE - Completes the level triggering level complete events.
LOAD_SCENE - Load the scene with the given name (scene must be in Build Settings).
LOCK - Lock the provided level.
UNLOCK - Unlock the provided level.
RESPAWN - Respawn the character at the given respawn point.
SET_ACTIVE_RESPAWN - Set the active respawn point.
START_EFFECT - Starts playing an effect set up with the FX system.
FLIP_GRAVITY - Flips gravity (requires character to supportFlippableGravity).
PLAY_ANIMATION - Plays an animation using a SpecialMovement_PlayAnimation component.
START_SWIM - Starts the character swimming, use when entering water.
STOP_SWIM - Stops the character swimming, use when exiting water.
ADD_SCORE - Adds the given value to the given score type.
RESET_SCORE - Resets the given score type to zero.
You can delay an action so that it doesn't take affect immediately. For example you may want to delay the character Respawn to give time for a particle effect to finish.
Warning: If you use many action delays you will notice a small garbage collection overhead. This is typically okay, but on mobile devices you may want to avoid action delays on events that occur regularly (like animation state changes).
The EventResponder can listen to any C# event that has event arguments that derive from System.EventArgs.
The following events are send by Platformer Pro components:
Loaded - Fired when the health information is loaded from the saved data.
Healed - Fired when the Characters health is increased.
Damaged - Fired when the Characters health is reduced.
Died - Fired when the Character dies.
GameOver - Fired when the Game ends.
ChangeAnimationState - Fired when animation state changed. Used by animation bridges to animate character, but can also be used to drive particle effects or sound effects (see also Sound Effects Bridge).
Respawned - Fired when the Character has respawned at a new location.
WillExitScene - Fired when the Character is about to leave the scene. Often used for clean-up.
CharacterLoaded - Fired when the Character has been loaded.
GamePaused - Fired when the game is paused.
GameUnPaused - Fired when the game unpaused.
ChangeAnimationState - Fired when animation state changed. Used by animation bridges to animate enemy.
CharacterDamaged - Fired when the Enemy causes damage to the player.
Collided - Fired when the Enemy runs in to a wall.
Damaged - Fired when the Enemy is damaged.
Died - Fired when the Enemy dies.
CollectItem - Triggered when the item is collected.
Open - Fired when the door is opened (triggers when open starts).
Closed - Fired when the door is closed (triggers when close starts).
Entered - Fired when the character enters the door (EnterableDoor only).
TriggerEntered - Fired when a trigger is entered.
TriggerExited - Fired when a trigger is exited.
LevelComplete - Character finished the level.
Loaded - Level manager data finished loading.
Respawned - Character was respawned.
SceneLoaded - Scene finished loading.
Note: this list is not exhaustive as we add new events all the time.