{{tag>dragonscript behavior}}
[[:start|Start Page]] >> [[main|DragonScript Scripting Language]] >> [[abstractions#behavior_elementsquick_and_easy_development|Behavior Elements: Quick and Easy Development]] >> **ECBehaviorLookedAt**
* [[behaviors_use_cases|Behaviors Explained: By Use-Case]]
* [[behaviors_a_to_z|Behaviors Explained: From A to Z]]
====== ECBehaviorLookedAt ======
Behavior element behavior adding support to track if actors look at element.
This behavior tracks if actors are looking at the element. If actors start looking at the element they are added to the list and listeners are notified. If the actors stop looking at the element they are removed from the list and listeners are notified. The actors can be an NPC or the player.
The behavior itself is passive. It requires to be triggered by the actor elements. The [[behavior_lookat|ECBehaviorLookAt]] behavior provides this functionality.
====== Instance Counts ======
This behavior can be used only once on an element. The behavior always has identifier empty string.
====== Element Class Properties ======
Element class properties have the prefix **lookedAt.**.
This behavior defines no element class properties.
====== Required Behaviors ======
This behavior does not required other behaviors to be present.
====== Optional Behaviors ======
This behavior does not support optional behaviors.
====== Persistency ======
This behavior does support element class to be persistable (setPersistable). Saves the list of actors looking at the element.
====== Events ======
This behavior supports adding listeners. These events can be received:
===== actorStartsLookingAt =====
Actors starts looking at object. Event contains //BehaviorElement// instance of actor now looking at object.
===== actorStopsLookingAt =====
Actors stops looking at object. Event contains //BehaviorElement// instance of actor no more looking at object.
====== API Documentation ======
#@LinkApiDocDEDS2_HTML~classDragengine_1_1Scenery_1_1ECBehaviorLookedAt.html,ECBehaviorLookedAt~@#.
Since DragonScript Module Version **1.1**
====== Use Cases ======
* Show outline and interact prompts if player looks at object.
* For NPCs to react to player (or other actors) looking at them (for example looking back at player).
* Show target information if player aims at objects.
====== Element Class Example ======
class ExampleElementClass extends BehaviorElementClass
public var ECBehaviorLookedAt lookedAt
public func new() super("ExampleElement")
// add looked at behavior. by itself this does nothing yet. add listeners to the
// behavior to react to looking-at changes. this is typically done by other
// behaviors to provide their functionality
lookedAt = ECBehaviorLookedAt.new(this)
end
end