private IEnumerator AttackAnimationCo(AttackDirections attackDirection) { switch (attackDirection) { case AttackDirections.FORWARD: _attackForwardGameObject.SetActive(true); break; case AttackDirections.UP: _attackUpGameObject.SetActive(true); break; case AttackDirections.DOWN: _attackDownGameObject.SetActive(true); break; } var timer = 0f; while (timer < _attackAnimationLength) { timer += Time.deltaTime; yield return(null); } switch (attackDirection) { case AttackDirections.FORWARD: _attackForwardGameObject.SetActive(false); break; case AttackDirections.UP: _attackUpGameObject.SetActive(false); break; case AttackDirections.DOWN: _attackDownGameObject.SetActive(false); break; } }
private void GoAttack(AttackDirections attackDirection) { var position = Vector2.zero; var size = Vector2.zero; switch (attackDirection) { case AttackDirections.FORWARD: position = _attackForwardTransform.position; size = _attackSize; var hitsForward = Physics2D.OverlapBoxAll(position, size, 0f, _attackableLayersForward); if (hitsForward != null && hitsForward.Length > 0) { _playerState.RecoilingX = true; // set to false by RecoilX Script //RecoilX(); foreach (var hit in hitsForward) { // damage enemies } } else { Debug.Log("no hit"); } break; case AttackDirections.UP: position = _attackUpTransform.position; size = new Vector2(_attackSize.y, _attackSize.x); var hitsUp = Physics2D.OverlapBoxAll(position, size, 0f, _attackableLayersUp); if (hitsUp != null && hitsUp.Length > 0) { foreach (var hit in hitsUp) { // damage enemies } } else { Debug.Log("no hit"); } break; case AttackDirections.DOWN: position = _attackDownTransform.position; size = new Vector2(_attackSize.y, _attackSize.x); var hitsDown = Physics2D.OverlapBoxAll(position, size, 0f, _attackableLayersDown); if (hitsDown != null && hitsDown.Length > 0) { // recoil only when spike hit if (hitsDown.Where(h => h.tag == "Spike").Count() > 0) { _playerState.RecoilingY = true; // set to false by RecoilY Script } //RecoilY(); EventManager.Instance.TriggerEvent(ActionNames.SPIKE_HIT.ToString()); foreach (var hit in hitsDown) { // damage enemies } } else { Debug.Log("no hit"); } break; } }