Game Development Reference
In-Depth Information
A configured Event Trigger with two events and a single action for each
Some of the new
UI
controls natively implement the
Event Trigger
behavior
using the interfaces described previously, but it is also provided separately should
you have the need to extend anything else with such a capability from
Editor
.
(Although Unity recommends using code or the built-in controls.)
It is worth noting that although the
Event Trigger
component
exists, Unity recommends you build your own scripts, mainly for
performance reasons. The
Event Trigger
component is bound to
all
events and
receives all
events by default. It then decides which
to act upon based on the component's configuration, so it's not as
performant as your own specific script. Keep this in mind and only
use the
Event Trigger
component if you really, really need it.
In short, the
Event Trigger
allows you to:
• Create an event hook in the inspector (Shown as
PointerClick
and
PointerExit
in the preceding screenshot)
• Attach the result of that event to another GameObject
• Select a property, script, or other attribute on the target object to manipulate
(shown as the
Image.sprite
property or the
RectTransform.
BroadcastMessage
method)
• If applicable, provide a value or input to the target call
What's even better is that you can attach as many different actions on the result of
the event. So if you wished, you could update several different GameObjects or
several different properties of a target GameObject on the result of a single event.
We'll cover this in more detail in
Chapter 3
,
Control, Control, You Must Learn
Control
when we cover the specific controls that implement this behavior,
just a taster for now.