Skip to main content

HealthBasedDigable

A class in Root.Township, the global namespace.

Diggable object (such as a dirt pile) that takes several digs to remove. Server tracks and saves its remaining health and syncs it to clients.

Constructors​

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

Fields​

5 private and internal fields
MemberWhat it is
private float currentHealthRemaining health from 1 down to 0; saved.
private float diggingHealthTotal digging damage needed to remove the object.
private PositionEvent onHealthChangedEffectsEvent raised with the position when a dig doesn't finish the object.
private FloatEvent onHealthChangedProgressEvent raised with dig progress from 0 to 1.
private MethodSyncStruct<bool> syncHealthNetwork message used to send health.

Methods​

MemberWhat it is
override void Dig(float diggingDamage)Server: lowers health by the damage over diggingHealth; removes it like a normal dig at zero, else syncs and plays hit effects.
override void Initialize()Sets up the health sync message.
override void OnConnected(Player player)Sends the current health to a joining player without effects.
2 private and internal methods
MemberWhat it is
private void RunEffects()Plays the hit effects at this position and reports progress as one minus health.
private void SyncHealth(IPlayer player, Stream stream, bool hasEffects)Reads or writes health and an effects flag; clients play the effects when the flag is set.