Skip to main content

PlayerDetect

A class in Root.Township, the global namespace.

Server: detects players whose feet are inside a sphere or box around this object and fires events as they enter and leave. Its shape is saved with the object.

Constructors​

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

Fields​

9 private and internal fields
MemberWhat it is
private Vector3 boundSizeSize of the local space box, when isUsingBounds is on.
private UnityEvent firstEnteredUnity event fired when the first player enters an empty area.
private HashSet<Player> inAreaBacking set for InArea.
private bool isUsingBoundsIf true, uses a box of boundSize instead of a sphere.
private UnityEvent lastLeftUnity event fired when the last player leaves.
private PlayerUnityEvent playerEnteredUnity event behind PlayerEntered.
private bool playerInAreaDebugInspector flag showing if any player is in the area.
private PlayerUnityEvent playerLeftUnity event behind PlayerLeft.
private float radiusSquaredThe sphere's radius, stored squared.

Properties​

MemberWhat it is
IReadOnlyCollection<IPlayer> InArea { get; }The players inside the area right now.

Events​

MemberWhat it is
event UnityAction<IPlayer> PlayerEnteredFires with the player when one enters the area.
event UnityAction<IPlayer> PlayerLeftFires with the player when one leaves the area.

Methods​

3 private and internal methods
MemberWhat it is
private void Awake()Turns the component off on clients, so it only runs on the server.
private void OnDrawGizmosSelected()Draws the detection sphere or box in the editor.
private void Update()Checks every player the entity is spawned for each frame and updates the area list, firing the enter and leave events.

Used in​

Members of other types that take, return or hold a PlayerDetect: