private void HitEnemy(EnemyHealth enemyHealth, Vector3 hitPoint) { if (!enemyHealth.AlreadyHit && !enemyHealth.IsDead) { DashingFeature enemyDashing = enemyHealth.GetComponent <DashingFeature>(); if (enemyDashing != null && enemyDashing.isActiveAndEnabled && enemyDashing.Dashing) { return; } enemyHealth.AlreadyHit = true; hitEnemies.Add(enemyHealth); EnemyControlManager enemyControl = enemyHealth.GetComponentInParent <EnemyControlManager>(); enemyControl.GetHit(); BlockingFeature enemyBlocking = enemyHealth.GetComponentInChildren <BlockingFeature>(); if (enemyBlocking != null && enemyBlocking.isActiveAndEnabled && enemyBlocking.Blocking) { Disable(); enemyBlocking.BlockHit(isPlayer, enemyBlocking.CharacterTransform.position - transform.position); GetComponentInParent <PlayerControlManager>().KnockBack(transform.position - enemyHealth.transform.position, isShort: true); anim.SetTrigger("recoil"); return; } enemyControl.KnockBack(enemyHealth.transform.position - transform.position, isShort: false); enemyHealth.TakeDamage(damage, hitPoint); //Debug.Log("Enemy hit"); } }
void Start() { anim = GetComponent <Animator>(); if (gameObject.tag == "Player") { isPlayer = true; playerControl = GetComponentInParent <PlayerControlManager>(); } else if (gameObject.tag == "Enemy") { isPlayer = false; enemyControl = GetComponentInParent <EnemyControlManager>(); } }
void Start() { health = GetComponentInChildren <EnemyHealth>(); traits = GetComponentInChildren <EnemyTraits>(); hasMelee = traits.Melee; hasRanged = traits.Ranged; hasBlock = traits.Block; hasDash = traits.Dash; if (hasDash) { dashing = GetComponentInChildren <DashingFeature>(); } controlManager = GetComponent <EnemyControlManager>(); player = GameObject.FindGameObjectWithTag("Player").transform; playerHealth = player.GetComponent <PlayerHealth>(); playerHasMelee = player.GetComponent <PlayerTraits>().Melee; if (playerHasMelee) { playerMeleeAttacking = player.GetComponentInChildren <MeleeAttackFeature>(); } playerHasBlock = player.GetComponent <PlayerTraits>().Block; if (playerHasBlock) { playerBlocking = player.GetComponentInChildren <BlockingFeature>(); } navAgent = GetComponent <NavMeshAgent>(); meleeRangeTracker = GetComponentInChildren <MeleeRangeTracker>(); currentState = EnemyState.Approach; }