public void DamageMob(int damage, GameObject firer, GameObject hitter = null) { //Debug.Log ("Damaging mob: " + this.name + "."); if (!m_isInvincible) { if (m_currentShield > 0) { //If shields are up, apply damage to the shield m_currentShield -= damage; if (m_currentShield <= 0) { ShieldOnOff(false); //if the shield gives out before all the damage is dealt, apply the remainder to the hull m_currentHealth += m_currentShield; if (m_currentHealth <= 0) { //Mob is dead :( OnMobDies(firer, hitter); } m_currentShield = 0; } if (hitter) { BeamBulletScript beam = hitter.GetComponent <BeamBulletScript>(); Vector3 position = beam ? beam.beamHit.point : hitter.transform.position; int dType = beam ? (int)beam.m_damageType : (int)hitter.GetComponent <BasicBulletScript>().m_damageType; float magnitude = beam ? beam.GetDamage() : hitter.GetComponent <BasicBulletScript>().GetDamage(); networkView.RPC("PropagateShieldWibble", RPCMode.All, position, dType, magnitude); } } else { //If no shields, apply damage directly to hull m_currentHealth -= damage; if (m_currentHealth <= 0) { //Mob is dead :( OnMobDies(firer, hitter); } } if (Network.isServer) { //If we're host, propagate the damage to the rest of the clients try { networkView.RPC("PropagateDamage", RPCMode.Others, m_currentHealth, m_currentShield); } catch (UnityException e) {} //Tell gamecontroller the capital ship is under attack if (this.tag == "Capital") { if (firer != null && firer.tag != "Asteroid") { m_GameStateController.GetComponent <GameStateController>().CapitalShipHasTakenDamage(); } } if (this.tag == "Enemy") { if (firer != null && firer.tag != "Asteroid") { if (GetHPPercentage() < 0.3f) { //Alert enemy it's dying and should kamikaze //Debug.Log("Enemy: " + this.name + " is enraged!"); this.GetComponent <EnemyScript>().AlertLowHP(firer); } else if (!hasBeenHitAlready) { hasBeenHitAlready = true; this.GetComponent <EnemyScript>().AlertFirstHit(firer); } else { this.GetComponent <EnemyScript>().NotifyEnemyUnderFire(firer); } } } } //Whatever happens, reset the shield cooldown ResetShieldRecharge(); } }