// Damage handling, supposed to be entirely server-side for core data. public void Hit( float baseAmount, GenericCharacter attacker, Vector3 hitPoint, Vector3 hitDirection) { Stats attackerStats = attacker.GetComponent <Stats>(); float amount = baseAmount * defenseMultiplier; if (attackerStats != null) { amount *= attackerStats.attackMultiplier; } if (isServer) { Health -= amount; } _character.OnReceiveDamage(amount, attacker, hitPoint, hitDirection); attacker.OnMakeDamage(amount, _character, hitPoint, hitDirection); if (!isServer) { return; } if (hitEffect != null) { var hit = Instantiate( hitEffect, hitPoint, Quaternion.LookRotation(hitDirection)); NetworkServer.Spawn(hit); // Destroy the effect after 2.15 seconds Destroy(hit, 2.15f); } if (Health <= 0.0f && !gameObject.GetComponent <GenericCharacter>().isDead) { gameObject.GetComponent <GenericCharacter>().isDead = true; if (deathEffect != null) { var ded = Instantiate( deathEffect, hitPoint, Quaternion.LookRotation(hitDirection)); NetworkServer.Spawn(ded); // Destroy the effect after 2.15 seconds if (deathEffectDuration > 0f) { Destroy(ded, deathEffectDuration); } } } }
protected void PlayAnimation(GenericCharacter character) { Animator animator = character.GetComponent <Animator>(); if (animator != null) { animator.Play("Attack"); } }