Skip to main content

Rock

A class in Root.Township, the global namespace.

A mineable boulder piece: a HealthObject that drops resources from its BoulderDefinition when killed. Usually set up by a RockCluster; the kill and drops run on the server.

Constructors​

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

Fields​

7 private and internal fields
MemberWhat it is
private Coroutine disablingHitFlagThe running DisableHitFlag coroutine, if any.
private float fadeTimeHitFlagHow long in seconds after a local hit the rock still counts as recently hit. Default 1.
private ImpactDetector impactDetectorThe ImpactDetector that reports tool hits on this rock.
private bool isInHitTimeTrue for a short time after the local player hit the rock, so destruction effects play on that client.
private ImpactHitWithTool lastHitThe last tool hit, used for haptics in OnDestroy. Never assigned in this code, so it stays null.
private MaterialGroup oresThe MaterialGroup whose material is swapped to the definition's ore material.
private Transform spawnPositionWhere dropped resources spawn.

Properties​

MemberWhat it is
BoulderDefinition Definition { get; private set; }The BoulderDefinition this rock uses for health, drops, ore material and destroyed effect. Set by Define.

Methods​

MemberWhat it is
void Define(BoulderDefinition definition)Applies a BoulderDefinition: sets maximum and current health, impact settings and the ore material. Does nothing if it's already that definition.
override void OnValidate2()Defaults spawnPosition to the rock's own transform.
protected override void Awake()Hooks KilledEffects to Killed and RegisterHit to the impact detector's Hit event.
protected virtual void SpawnResources(DamageData rawHit)Picks a drop count from DropCount, rolls each drop by weight from ResourcesDropChances, spawns them at spawnPosition and throws them toward the hitter's head.
5 private and internal methods
MemberWhat it is
private IEnumerator DisableHitFlag() (iterator)Coroutine that clears isInHitTime after fadeTimeHitFlag seconds.
private IEnumerator ExecuteActionNextFrame(Action action) (iterator)Coroutine that runs an action one frame later. Used to set the velocity of spawned drops once their rigidbody exists.
private void KilledEffects(DamageData swing)Server: on death plays the destroyed effect, triggers haptics for the tool holders, spawns the drops and destroys the entity.
private void OnDestroy()Client: if the local player hit the rock recently, plays the destroyed effect and haptics locally, then unhooks the hit handler.
private void RegisterHit(ImpactHit hit)When the local player hits the rock with a tool, sets isInHitTime and restarts the timer that clears it.