Playground Actions

Vérifié avec version: 2017.4

-

Difficulté: Débutant

Actions are scripts that don’t work on their own, but need to be executed by Conditions. Only if the Condition is verified, the Action is executed. You can recognise Action scripts because they have a little yellow "then" tag at the top-left corner of their icon.

description

Action scripts all feature the concept of "success". It means that some actions can fail, and if they do, the Condition that is playing them will interrupt the chain of Actions and stop.

Adding and removing Actions

Actions can be added like any other regular component, but on their own they won’t do anything - they always need to be connected to a Condition.

For this reason, it makes sense not to add Actions in the usual way but to use the dropdown menu at the bottom of Conditions’ Gameplay Actions list. This both adds the Action component and connects it to the list. Similarly, the minus icon both removes the item in the list and the component from the GameObject, leaving it clean.

description

If you want to place an Action on another obdescriptionject that has the Condition, simply add the Action to it as a normal component, then go to the list and use the last option, "Empty Slot". Finally, you need to drag the GameObject that has the Action onto the list slot that you just added.

More info in the Gameplay Actions section of Conditions.

ConsumeResourceAction

description

Requires: nothing

ConsumeResourceAction is an action that acts only if a certain condition is verified: the specified Type of Resource needs to be present in the player’s inventory in the quantity specified in Amount Needed.

If this is true, that amount of resources is consumed and the following Actions are executed.

If false, then no resource is consumed and the list of Actions is stopped (meaning any following Action is not executed).

Like in the ResourceAttribute script, the Add/Remove types button allows you to define resource types. See Definining resource types for more info and a rundown of what resources mean.

description

CreateObjectAction

Requires: nothing

description

CreateObjectAction generates a new object from a prefab (Prefab to Create).

To decide where the new object is created, you can use New Position, which initially is in World Space (meaning 0,0 is the origin). When Relative to this Object is checked, New Position can be considered Local Space.

DestroyAction

description

Requires: nothing

description

DestroyAction can be used to remove objects from the game.

The Target property can have two values: This Object (pretty self-explanatory) and Object That Collided. When using the latter, this Action needs to be connected to either a ConditionArea or ConditionCollision, or it will fail.

You have the option to specify a Death Effect, that is another object that gets generated when the Target object is destroyed. This could be a particle system, or other objects (like debris, a broken version of the object being destroyed, etc.).

DialogueBalloonAction

description

Requires: nothing

description

The DialogueBalloon script allows to put simple dialogues in the game. You can see an example of it in the Roguelike example scene.

description

The first block of properties, Text to Display, Background Color and Text Color are pretty self-explanatory.

Target Object, if set, allows the text to appear above a character or an object. If it’s not set, the text just appears in the middle of the screen.

Disappear Mode allows for two values: Button Press requires the user to press a key (Key to Press) to remove the dialogue, while with Time the dialogue disappears after the seconds specified in Time to Disappear.

Regardless of how the dialogue is removed, you can connect another DialogueBalloonAction in the last slot, Following Text, to create a continuous dialogue.

Tip: Use chained DialogueBalloonAction scripts with no target and in Button Press Disappear Mode to create small tutorials for your game. Or, by chaining several DialogueBalloonActions and focusing them on different characters with the Target Object property, you can create conversations between two or more characters.

LoadLevelAction

description

Requires: nothing

description

LoadLevelAction adds the ability to load Unity scenes from Conditions.

The Scene to Load property displays a dropdown menu which includes all of the scenes that have been added to the Build Settings menu (File > Build Settings…). To be loaded, a scene needs to be added to the list and also be enabled.

The first item, "RELOAD LEVEL", just reloads the current scene so it’s useful to reset the state of the game after game over.

OnOffAction

description Requires: nothing

description

OnOffAction is a simple action to turn an object on and off, meaning setting its Active flag to true or false. You need to select the target in Object to Affect in order for this to work.

Just Make Invisible allows you to turn on/off a SpriteRenderer instead, meaning the object is still part of the gameplay, including any collision events it might have.

OnOffAction always "flips the switch", setting the active flag to its opposite. This means the second time the Action is executed on the same object it restores its previous state, and so on.

Tip: If you want to set an object on/off in an absolute way (meaning the second time there will be no effect), you can use just a regular UnityEvent, enabling Custom Actions on the Condition and selecting SetActive on the target GameObject:

TeleportAction

description

Requires: nothing

description

TeleportAction moves an object instantly to a new location. If nothing is assigned in Object to Move, the same object that has the script is teleported. The New Position property is in World Space.

For objects that have a Rigidbody2D, enabling Stop Movements means that in addition to be teleported, they are also stopped, meaning their speed and torque are zeroed - which is good for resetting the game state (for instance, after scoring in a sports game).