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"); } }
private void Awake() { damage = baseDamage; weaponAudio = GetComponent <AudioSource>(); weaponcollider = GetComponent <CapsuleCollider>(); weaponcollider.enabled = false; outerCollider.enabled = false; anim = GetComponentInParent <Animator>(); baseSpeed = anim.speed; speed = baseSpeed; rand = new Random(); normalClip = GetAnimationTime("NormalAttack01_SwordShield"); comboClip = GetAnimationTime("NormalAttack02_SwordShield"); if (isPlayer) { hitEnemies = new List <EnemyHealth>(); } else { GameObject player = GameObject.FindGameObjectWithTag("Player"); playerHealth = player.GetComponent <PlayerHealth>(); playerDashing = player.GetComponent <DashingFeature>(); playerBlocking = player.GetComponentInChildren <BlockingFeature>(); } }
public void Initialize(RangedAttackFeature user, float speed, float range, float damage, Vector3 direction = new Vector3()) { this.user = user; this.speed = speed; this.range = range; this.damage = damage; Vector3 originPosition = user.ShootOrigin.position; Quaternion originRotation; if (direction == new Vector3()) { originRotation = user.ShootOrigin.rotation; } else { originRotation = Quaternion.LookRotation(direction); } InitializeEffect(originPosition, originRotation); if (!user.IsPlayer) { GameObject player = GameObject.FindGameObjectWithTag("Player"); playerHealth = player.GetComponent <PlayerHealth>(); playerDashing = player.GetComponent <DashingFeature>(); playerBlocking = player.GetComponentInChildren <BlockingFeature>(); } else { outerBehaviour = GetComponentInChildren <OuterProjectileBehaviour>(); } }
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; }
private void OnCollisionEnter(Collision collision) { if (collision.collider.tag == "Environment") { Sizzle(); return; } if (ByPlayer) { //if (collision.collider.tag == "Projectile" && // !collision.collider.GetComponent<ProjectileBehaviour>().ByPlayer) //{ // outerBehaviour.Clear(); // Explode(collision); // return; //} EnemyHealth enemyHealth = collision.collider.GetComponent <EnemyHealth>(); if (collision.collider.tag == "Enemy" && !enemyHealth.IsDead) { outerBehaviour.Clear(); Explode(collision); DashingFeature enemyDashing = collision.collider.GetComponent <DashingFeature>(); if (enemyDashing != null && enemyDashing.isActiveAndEnabled && enemyDashing.Dashing) { return; } enemyHealth.GetComponentInParent <EnemyControlManager>().GetHit(); BlockingFeature enemyBlocking = collision.collider.GetComponentInChildren <BlockingFeature>(); if (enemyBlocking != null && enemyBlocking.isActiveAndEnabled && enemyBlocking.Blocking) { Sizzle(); enemyBlocking.BlockHit(ByPlayer, transform.forward, reflect: true); return; } enemyHealth.GetComponentInParent <EnemyControlManager>().KnockBack(enemyHealth.transform.position - transform.position, isShort: false); enemyHealth.TakeDamage(damage, enemyHealth.transform.position); //Debug.Log("Enemy hit"); } } else { //if (collision.collider.tag == "Projectile" && // collision.collider.GetComponent<ProjectileBehaviour>().ByPlayer) //{ // Explode(collision); // return; //} if (collision.collider.tag == "Enemy") { Sizzle(); } else if (collision.collider.tag == "Player" && !playerHealth.IsDead) { if (playerDashing != null && playerDashing.isActiveAndEnabled && playerDashing.Dashing) { Sizzle(); return; } playerHealth.GetComponentInParent <PlayerControlManager>().GetHit(); if (playerBlocking != null && playerBlocking.isActiveAndEnabled && playerBlocking.Blocking) { Sizzle(); playerBlocking.BlockHit(ByPlayer, transform.forward, reflect: true); return; } Explode(collision); playerHealth.GetComponentInParent <PlayerControlManager>().KnockBack(playerHealth.transform.position - transform.position, isShort: false); playerHealth.TakeDamage(damage); user.GetComponentInParent <FitnessTracker>().DamagedPlayer(damage); inflictedDamage = true; //Debug.Log("Player hit"); } else if (collision.collider.tag == "OuterCharacter") { outerHit = true; } } }