Playground Conditions

確認済のバージョン: 2017.4

-

難易度: 初級

Conditions are very similar to If Statements in programming, meaning that they act as a gateway to other behaviours. If the condition is verified, then the attached Actions are executed. See Action scripts for more details on what Conditions can execute.

Condition scripts have a little purple "if" tag at the top-left corner of their icon.

description

All Condition scripts have some common properties which are described below.

Gameplay Actions

The Gameplay Actions is a list of Action scripts that are executed when the requirement of this Condition script is met. Once that happens, Unity executes the Actions in this list until one of them fails (only a few Action can fail). If the Action doesn’t fail, then the next one is executed. At the end of the list, Custom Actions (if present, see below) are carried out.

A list of empty Actions would look like this:

description

Pressing the plus icon reveals a list of the Actions available to add:

description

They correspond exactly to the scripts in the Action category. If you select any of them, the script is added as a component and automatically connected to the list.

Note: Action scripts need to be connected in the Gameplay Actions list to work. Simply adding an Action script to a GameObject will not execute it.
Tip: At the end of the dropdown, you also have an option to add an empty slot. That’s really useful to be able to connect an Action present on another GameObject. This way you can break your logic into parts, making it easier to manage. To see this in practice, open the Roguelike example game and select the object named InvisibleTrigger. Notice how 2 of the Actions are on separate objects parented to this one.

Custom Actions

Similarly to Gameplay Actions, Custom Actions are executed when the requirement of the Condition script is met. It’s not necessary to use them, so if Use Custom Actions is unchecked, no custom action is executed.

Checking the option reveals a list of Unity Events, in which you can connect here anything you would normally use an UnityEvent for.

description

Because of this, they really allow you to expand the gameplay aspect of your game: if you know programming, you can write a simple script and expose a public function, and then connect it in here. This way your script can be called by one of the default Condition scripts of the Playground. This is a great way for teachers to quickly extend the functionality of the Playground during a workshop.

Another use would be to connect in here standard Playground public functions. A good example is the UI Script and its GameWon and GameOver functions. By wiring one of them into the Custom Actions list of a Condition, you can for instance create a winning condition when an object collides with something else, or enters an area.

description

ConditionArea

description

Requires: a Collider2D set as Trigger

ConditionArea requires a Collider2D set as trigger. Event Type determines when the event occurs: on entering the area, on leaving it, or while staying inside (if you select this last one, a Frequency parameter is revealed to determine how often it happens).

Because you probably don’t want any object to trigger the event, Filter by Tag allows to restrict the event happening only if a specific category of objects enters the area. It is common to use Player, but you can use whatever you prefer.

Happen Only Once allows the condition to be ignored after the event has happened once.

Gameplay Actions and Custom Actions are common to all Conditions, so you can find more info in the general sections: Gameplay / Custom.

ConditionCollision

description

Requires: nothing

description

ConditionCollision is a simple condition to make something happen when an object collides with the one that has this script. As with other conditions, you can filter which type of object actually produces the event by setting a tag in Filter by Tag.

Happen Only Once allows the condition to be ignored after the event has happened once.

Gameplay Actions and Custom Actions are common to all Conditions, so you can find more info in the general sections: Gameplay / Custom.

ConditionKeyPress

description

Requires: nothing

description

ConditionKeyPress is a generic way of binding an Action to a key press. In addition to choosing which key with Key to Press, you can choose which type of key event to listen to with Event Type: Just Pressed (similar to GetKeyDown), Released (GetKeyUp) or Kept Pressed (GetKey). As with other continuous actions, Kept Pressed mode has a Frequency property.

Happen Only Once allows the condition to be ignored after the event has happened once.

Gameplay Actions and Custom Actions are common to all Conditions, so you can find more info in the general sections: Gameplay / Custom.

ConditionRepeat

description

Requires: nothing

description

To make a programming comparison, ConditionRepeat is more like a WHILE than an IF. It executes the list of Actions repeatedly without user input or interaction. It supports a Frequency, and an Initial Delay.

Gameplay Actions and Custom Actions are common to all Conditions, so you can find more info in the general sections: Gameplay / Custom.