Skip to main content

NearbyPlayerTracker

A class in Root.Township, the global namespace.

Server-side component that watches one player and fires events when their head enters or leaves a radius around it. Starts disabled until Track is called.

Constructors​

MemberWhat it is
NearbyPlayerTracker()Unity makes components itself; use AddComponent or spawn a prefab instead of new.

Fields​

7 private and internal fields
MemberWhat it is
private PlayerEvent enteredRadiusEvent fired when the player comes within the radius.
private bool isFirstUnused.
private PlayerEvent leftRadiusEvent fired when the player leaves the radius or is destroyed.
private IPlayer playerThe player being tracked.
private float radiusDistance from this object to the player's head that counts as near.
private PlayerEvent stoppedTrackingEvent fired when tracking stops.
private bool wasWithinWhether the player was inside on the last check.

Methods​

MemberWhat it is
void StopTracking()Fires stoppedTracking, unhooks the player's destroy events and disables the component.
void Track(IPlayer player)Server: starts tracking a player, fires entered or left at once, and watches for them being destroyed.
6 private and internal methods
MemberWhat it is
private void Awake()Disables the component until tracking starts.
private void CheckWithin(bool isForced)Checks the player's head distance and fires entered or left when it changes (or always when forced).
private void LateUpdate()Checks the distance each frame while tracking.
private void OnDestroy()Stops tracking if a player is set.
private void OnDrawGizmosSelected()Draws the radius.
private void PlayerDestroyed(NetworkEntity entity, bool isUnload)Fires the left event when the player or their body is destroyed.