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.
- Listed in Global namespace: M to O
- Inherits or implements
MonoBehaviour
Constructors
| Member | What it is |
|---|---|
NearbyPlayerTracker() | Unity makes components itself; use AddComponent or spawn a prefab instead of new. |
Fields
7 private and internal fields
| Member | What it is |
|---|---|
private PlayerEvent enteredRadius | Event fired when the player comes within the radius. |
private bool isFirst | Unused. |
private PlayerEvent leftRadius | Event fired when the player leaves the radius or is destroyed. |
private IPlayer player | The player being tracked. |
private float radius | Distance from this object to the player's head that counts as near. |
private PlayerEvent stoppedTracking | Event fired when tracking stops. |
private bool wasWithin | Whether the player was inside on the last check. |
Methods
| Member | What 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
| Member | What 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. |