Skip to content
This repository was archived by the owner on Aug 14, 2019. It is now read-only.

EnemyTargeting.cs

ErikOverflow edited this page Apr 9, 2019 · 1 revision
Dependencies:
  • Collider2D set as a Trigger
  • GameEventListener listening to the PlayerDied GameEvent
Methods:
  • PlayerDied() - Releases target if the player dies (So we don't have enemies humping a corpse)
Events:
  • OnTargetLost - Invoked when a target leaves the range of the Collider
  • OnNewTargetAcquired - Invoked when a target enters the range of the Collider
Fields:
  • target - Current target
General Overview:

When a target enters the range of the Trigger Collider2D, the target is first checked to see if it has a CharacterHealth component, then it is set as the current target. Then OnNewTargetAcquired is invoked. If and when that transform leaves the Trigger, OnTargetLost is invoked. If the PlayerDied() is called externally the target is also set to null and OnTargetLost is invoked. The Physics collision matrix is configured to prevent Enemies from colliding with eachother, so we do not need to confirm that the collision contains anything beyond CharacterHealth.

Clone this wiki locally