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.
- Listed in Global namespace: Q to R
- Inherits or implements
HealthObject
Constructors
| Member | What it is |
|---|---|
Rock() | Unity makes components itself; use AddComponent or spawn a prefab instead of new. |
Fields
7 private and internal fields
| Member | What it is |
|---|---|
private Coroutine disablingHitFlag | The running DisableHitFlag coroutine, if any. |
private float fadeTimeHitFlag | How long in seconds after a local hit the rock still counts as recently hit. Default 1. |
private ImpactDetector impactDetector | The ImpactDetector that reports tool hits on this rock. |
private bool isInHitTime | True for a short time after the local player hit the rock, so destruction effects play on that client. |
private ImpactHitWithTool lastHit | The last tool hit, used for haptics in OnDestroy. Never assigned in this code, so it stays null. |
private MaterialGroup ores | The MaterialGroup whose material is swapped to the definition's ore material. |
private Transform spawnPosition | Where dropped resources spawn. |
Properties
| Member | What it is |
|---|---|
BoulderDefinition Definition { get; private set; } | The BoulderDefinition this rock uses for health, drops, ore material and destroyed effect. Set by Define. |
Methods
| Member | What 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
| Member | What 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. |