/// <summary> /// Given: Information about how the entity has hit. /// /// Called whenever the entity has taken damage. /// If the entity has zero health, onDie is called /// </summary> public virtual void takeDamage(HitRegister hit) { _currentHealth -= hit.damageDone; if (_currentHealth <= 0f) { onDie(hit); } }
public override void onDie(HitRegister deathHit) { if (isDestroyed) { return; } if (mainBuilding) { Destroy(mainBuilding); } GameObject g = Instantiate(destroyedGameObject, transform.position, destroyedGameObject.transform.rotation, transform) as GameObject; float mass = Random.Range(debrisInfo.massRange.x, debrisInfo.massRange.y); float drag = Random.Range(debrisInfo.dragRange.x, debrisInfo.dragRange.y); foreach (Transform t in g.transform) { if (t.GetComponent <Rigidbody>()) { Rigidbody rb = t.GetComponent <Rigidbody>(); rb.AddExplosionForce(deathHit.hitPower * 100, deathHit.hitPoint, Vector3.Distance(transform.position, deathHit.hitPoint)); rb.mass = mass; rb.drag = drag; } } creditsGain = Random.Range(creditGainRange.x, creditGainRange.y); for (int i = 0; i < creditsGain; i++) { Rigidbody rb = Instantiate(creditPrefab, transform.position, Quaternion.identity).GetComponent <Rigidbody>(); rb.AddExplosionForce(deathHit.hitPower * 100, deathHit.hitPoint, Vector3.Distance(transform.position, deathHit.hitPoint)); } Economy.playerCredits = creditsGain; Debug.Log(Economy.playerCredits); if (!multiDestroy) { isDestroyed = true; } }
/// <summary> /// Called whenever the entity has died /// </summary> public virtual void onDie(HitRegister deathHit) { Debug.Log("On Die Called"); }