void AttackTarget() { // Stop moving and look at the target walking = false; agent.ResetPath(); transform.LookAt(new Vector3(playerPos.x, transform.position.y, playerPos.z)); // If you are not currently attacking, attack target if (!currentlyAttacking && !blocking && !takingDamage) { currentlyAttacking = true; // Attack actions(s) CasterWeapon newWeapon = null; switch (attackPattern[currentAttackIndex]) { case AttackPatternActions.Missile: newWeapon = missileWeapons[Random.Range(0, missileWeapons.Count)]; break; case AttackPatternActions.Bolt: newWeapon = boltWeapons[Random.Range(0, boltWeapons.Count)]; break; case AttackPatternActions.Shield: newWeapon = shieldWeapons[Random.Range(0, shieldWeapons.Count)]; break; case AttackPatternActions.Dash: Dash(3); Invoke(nameof(ResetAttack), 5f); break; case AttackPatternActions.Summon: newWeapon = summonWeapons[Random.Range(0, summonWeapons.Count)]; break; case AttackPatternActions.Throw: newWeapon = throwWeapons[Random.Range(0, throwWeapons.Count)]; break; } if (newWeapon != null) { weapon = newWeapon; anim.SetInteger("CastType", weapon.castAnimationType); anim.SetTrigger("Cast"); // StartCoroutine(CastWeapon(weapon)); } currentAttackIndex += 1; if (currentAttackIndex > attackPattern.Count - 1) { currentAttackIndex = 0; } } }
IEnumerator CastWeapon(CasterWeapon weapon) { //weapon.PlayWindupParticles(); yield return(new WaitForSeconds(weapon.animationTime)); weapon.Fire(gameObject); yield return(new WaitForSeconds(weapon.cooldown)); currentlyAttacking = false; waitTime += weapon.cooldown + actionCooldownTime; }