protected void AttackTarget() { if (target != null) { if (Vector3.Distance(target.transform.position, transform.position) < attackRange) { Character character = target.GetComponent <Character>(); if (character != null) { DMGInfo dmgInfo = new DMGInfo(this.gameObject, Random.Range(10, 15), 0.5f); character.TakeDamage(dmgInfo); // meleeAttackRange.SetActive(false); } } } }
public void TakeDamage(DMGInfo dmgInfo) { if (dead) { return; } health = Mathf.Clamp(this.health - Mathf.Abs(dmgInfo.damage), 0, maxHealth); if (animator != null) { animator.SetTrigger("DMG"); } SoundController.PlaySound(damagedSounds[Random.Range(0, damagedSounds.Length)]); UpdateHealthbar(); if (health <= 0) { Death(); } }