Platformer PRO has its own trigger system which can be used to trigger changes in your game.
You can also get started with triggers by following the intro tutorial:
The following trigger types are available:
|Triggers effects when the Character gets within a certain distance (shown by the Orange circle).|
|Triggers effect when the Character walks through it from the direction indicated by the arrows.|
|A platform that also acts as a trigger. Can be set up to respond to a character landing on it or when a character headbutts it.|
A wrapper around a standard Unity Collider2D set up as a trigger. Triggers the same way as a Unity trigger but also allows you to easily attach platforms and have conditions like requiring an item.
For consistency we recommend you use the Unity Trigger wrapper instead of directly using a Unity Trigger but this is not required.
Triggers can automatically do something to one or more receivers. Receivers are configured by adding a list item and dropping a GameObject or Component reference in to the Receiver field.
Once a receiver is added the scene view will show a line from the trigger to the receiver (assuming gizmos are on for the trigger):
Once connected to a receiver the trigger can perform various actions on the receiver when the trigger is entered or left. The following actions are available:
|SEND_MESSAGE||Sends a message to a GameObject.||GameObject|
|ACTIVATE_PLATFORM||Turns a platform on.||Platform|
|DEACTIVATE_PLATFORM||Turns a platform off.||Platform|
|ACTIVATE_GAMEOBJECT||Activates a GameObject.||GameObject|
|DEACTIVATE_GAMEOBJECT||Deactivates a GameObject.||GameObject|
|CHANGE_CAMERAZONE||Triggers a camera zone switch (with associated animation if configured).||PlatformCamera|
|SWITCH_SPRITE||Changes a sprite.||SpriteRenderer|
|SHOW_DIALOG||Shows a dialog.||Dialog|
|HIDE_DIALOG||Hides a dialog.||Dialog|
|OPEN_DOOR||Opens a door.||Door|
|CLOSE_DOOR||Closes a door.||Door|
|ACTIVATE_SPAWN_POINT||Activates a spawn point.||R|
|PLAY_ANIMATION||Plays an animation.||Animator.|
*Note that the reciever is always a GameObject. When a component type is listed it means the GameObject must have a component of the given type.
Note: For more options see Trigger Events below.
Most triggers allow you to apply a conditions so that they only activate when the conditions are met.
Required Item - Character must have an Inventory and the Inventory must contain an item which has a type that is an exact match of Required Item or the trigger will not trigger.
Required Component - The referenced component must be present, active and enabled, or the trigger will not trigger. You can use this, for example, to have triggers that only respond to characters with specific movements enabled, for example only trigger when the Character has their weapon out.
Note: Some triggers have other conditions, for example a one-way trigger allows you to specify a direction and speed via the Velocity field.
Note: You can also use Additional Conditions with triggers, For example to require a certain key press or a certain speed to activate the trigger, see: https://jnamobile.zendesk.com/hc/en-gb/articles/219330268-Additional-Conditions
Other Trigger Options
One Shot - Trigger will only fire once.
Auto Leave time - After the trigger is entered, wait Auto Leave Time amount of seconds and then automatically trigger the leave actions, even if the character has not left the trigger. A non-zero value will also prevent the leave action being triggered when the character leaves the trigger.
If you wish to do something else (i.e. somethinbg that is not available in the tirgger actions) when a trigger is entered or left you can use an Event Responder in conjunction with the trigger. Triggers send the following events:
TriggerEntered - Fired when trigger is entered.
TriggerExited - Fired when trigger is left.
Nothing prevents you from using standard Unity triggers in your game. We suggest that you add the UnityTrigger wrapper to the GameObject the has your Collider2D on it: this enables you to use the rest of the trigger capabilities while still using Unity triggers. You do not have to do this.
Typically you do not need to add a special collider to the Character to trigger the Unity triggers, because most characters already have a HurtBox collider configured. Keep in mind that the layer of your trigger must be configured in the the Physics2D settings to collide with the layer of your characters collider.
The recommended layers are Character for the character hurt box and Collectable_Projectile for the trigger.
Remember: By default raycasts hit triggers (its a Unity Physics2D setting) and that means that your character will not be able to walk through triggers that are in the geometry layer!