private IEnumerator RangedAttack() { IsRangedAttacking = true; Events.OnRangedAttackBegin.InvokeSafe(); Projectile projectile = _rangedAttackPool.GetInstance <Projectile>(null); Vector3 position = _collider.bounds.center; Vector3 direction = Vector3.zero; float vertical = CharacterYoke.GetAxis(InputAction.MoveVertical); if (vertical != 0.0f) { if (vertical < 0.0f) { //Trying to hit down //If we're on the ground, we can't slash down if (IsGrounded) { yield break; } position.y -= _collider.bounds.extents.y; direction = Vector3.down; } else { position.y += _collider.bounds.extents.y; direction = Vector3.up; } } else { if (FacingDirection == Facing.Right) { direction = Vector3.right; position.x += _collider.bounds.extents.x; } else { direction = Vector3.left; position.x -= _collider.bounds.extents.x; } } projectile.transform.position = position; projectile.Setup(this, Config.BaseRangedDamage, direction * Config.ProjectileSpeed, _rangedAttackPool); projectile.OnHit += OnRangedHit; projectile.OnReturnToPool += OnProjectileReturnToPool; yield return(new WaitForSeconds(Config.RangedAttackSpeed)); IsRangedAttacking = false; Events.OnRangedAttackEnd.InvokeSafe(); }
protected IEnumerator MeleeAttack() { _meleeAttack.transform.localScale = Vector3.zero; Vector3 position = _collider.bounds.center; float target = 1.0f; float vertical = CharacterYoke.GetAxis(InputAction.MoveVertical); if (vertical != 0.0f) { if (vertical < 0.0f) { //Trying to hit down //If we're on the ground, we can't slash down if (IsGrounded) { yield break; } _meleeAttack.transform.localRotation = Quaternion.Euler(0.0f, 0.0f, 90.0f); position.y -= _collider.bounds.extents.y; } else { _meleeAttack.transform.localRotation = Quaternion.Euler(0.0f, 0.0f, -90.0f); position.y += _collider.bounds.extents.y; } } else { _meleeAttack.transform.localRotation = Quaternion.Euler(0.0f, 0.0f, 0.0f); if (FacingDirection == Facing.Right) { target = -1.0f; position.x += _collider.bounds.extents.x; } else { target = 1.0f; position.x -= _collider.bounds.extents.x; } } IsMeleeAttacking = true; Events.OnMeleeAttackBegin.InvokeSafe(); _meleeAttack.transform.position = position; _meleeAttack.SetActive(true); float duration = 0.0f; float t = 0.0f; while (t <= 1.0f) { _meleeAttack.transform.localScale = new Vector3(Mathf.Lerp(0.0f, target, t), 1.0f, 1.0f); duration += Time.deltaTime; t = duration / Config.MeleeAttackSpeed; yield return(null); } _meleeAttack.SetActive(false); IsMeleeAttacking = false; _meleeAttackEndTime = Time.time; Events.OnMeleeAttackEnd.InvokeSafe(); }