Skip to main content

FakePlayerHealth

A class in Root.Township, the global namespace.

A training dummy that shows the damage it takes as popups and a text list of recent hits. The server works out the damage and syncs the popup to clients.

Constructors​

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

Fields​

7 private and internal fields
MemberWhat it is
private float damageLast damage value, sent with the popup.
private Queue<float> lastDamagesRecent damage values shown in the text.
private float minDamageValueDamage at or below this isn't added to the text list.
private Vector3 pointLast hit point, sent with the popup.
private int showLastXDamagesHow many recent hits to list (0 to 10).
private MethodSync syncPopupMethod sync that sends popups to clients.
private Text textCanvasUI text that lists recent damage.

Methods​

MemberWhat it is
override void Initialize()Creates the method sync used to send damage popups.
override void ReceiveDamage(float healthDamage, float crippleDamage, DamageData damage = null)Server: for impact hits, applies the server's PvP rules to player tool hits, records the damage and sends a popup to clients. Doesn't lower any health.
4 private and internal methods
MemberWhat it is
private void OnValidate()Editor: shows the text only if showLastXDamages is above 0.
private void ShowPopup(Vector3 position, float damage)Spawns a red damage popup at a position.
private void SyncPopup(IPlayer player, Stream stream)Sends the hit point and damage. Client: shows the popup when received.
private void UpdateLastDamageText()Trims the recent damage list to showLastXDamages and writes it to the text.