IEnumerator SlashRoutine() { slashState = SlashState.Slashing; yield return(new WaitForSeconds(0.4f)); DoDamage(); yield return(new WaitForSeconds(0.9f)); if (slashState == SlashState.Comboing) { _animController.CrossFade("Backhand", 0.2f); StartCoroutine(ComboRountine()); } else { slashState = SlashState.None; } }
public override void Update() { if (!m_attack.IsActive) { return; } switch (m_slashState) { case SlashState.Inactive: if (TouchInput.IsScreenTouched) { InitSlash(); m_slashState = SlashState.Initialised; } break; case SlashState.Initialised: if (TouchInput.IsScreenTouched) { UpdateSlashPositions(); if (HasSlashOccured()) { _drawFlag = true; m_slashState = SlashState.Slashing; } } else { m_slashState = SlashState.Inactive; } break; case SlashState.Slashing: if (TouchInput.IsScreenTouched) { UpdateSlashPositions(); UpdateSlash(); if (IsSlashTooLong()) { Vector2 direction = (_endPosition - _startPosition); direction.Normalize(); _endPosition = _startPosition + _maxLength * direction; //Do collisions DestructibleComponent.DestructibleColliders[(int)AttackType.Slash].DoCollision(m_sliceCollider, null); m_slashState = SlashState.Vanishing; break; } else if (HasSlashStopped()) { //Do collisions DestructibleComponent.DestructibleColliders[(int)AttackType.Slash].DoCollision(m_sliceCollider, null); m_slashState = SlashState.Vanishing; break; } } else { m_slashState = SlashState.Inactive; } break; case SlashState.Vanishing: //Starts another slash immediately if the user taps the screen when the slash is still dissapearing if (TouchInput.IsScreenTapped) { m_slashState = SlashState.Inactive; Update(); return; } _shrinkingRatio = Math.Min(_shrinkingRatio + ShrinkSpeed, 1); if (_shrinkingRatio == 1) { m_slashState = SlashState.Inactive; _drawFlag = false; } break; } UpdateVertices(); }
public override void Update() { if (!m_attack.IsActive) return; switch (m_slashState) { case SlashState.Inactive: if (TouchInput.IsScreenTouched) { InitSlash(); m_slashState = SlashState.Initialised; } break; case SlashState.Initialised: if (TouchInput.IsScreenTouched) { UpdateSlashPositions(); if (HasSlashOccured()) { _drawFlag = true; m_slashState = SlashState.Slashing; } } else m_slashState = SlashState.Inactive; break; case SlashState.Slashing: if (TouchInput.IsScreenTouched) { UpdateSlashPositions(); UpdateSlash(); if (IsSlashTooLong()) { Vector2 direction = (_endPosition - _startPosition); direction.Normalize(); _endPosition = _startPosition + _maxLength * direction; //Do collisions DestructibleComponent.DestructibleColliders[(int)AttackType.Slash].DoCollision(m_sliceCollider, null); m_slashState = SlashState.Vanishing; break; } else if (HasSlashStopped()) { //Do collisions DestructibleComponent.DestructibleColliders[(int)AttackType.Slash].DoCollision(m_sliceCollider, null); m_slashState = SlashState.Vanishing; break; } } else m_slashState = SlashState.Inactive; break; case SlashState.Vanishing: //Starts another slash immediately if the user taps the screen when the slash is still dissapearing if (TouchInput.IsScreenTapped) { m_slashState = SlashState.Inactive; Update(); return; } _shrinkingRatio = Math.Min(_shrinkingRatio + ShrinkSpeed, 1); if (_shrinkingRatio == 1) { m_slashState = SlashState.Inactive; _drawFlag = false; } break; } UpdateVertices(); }
void Update() { float horizontalInput = Input.GetAxis("Mouse X"); float verticalInput = Input.GetAxis("Vertical"); float horizontalInputKeys = Input.GetAxis("Horizontal"); float speed = _moveSpeed; bool leftShiftDown = Input.GetKeyDown(KeyCode.LeftShift); bool leftShiftUp = Input.GetKeyUp(KeyCode.LeftShift); bool mouseClick = Input.GetMouseButtonDown(0); bool blockDown = Input.GetMouseButtonDown(1); bool blockUp = Input.GetMouseButtonUp(1); bool isSlashing = _animController.GetCurrentAnimatorStateInfo(0).IsName("Slash"); bool mouseIsClicking = false; if (Input.GetKeyDown(KeyCode.Escape)) { Cursor.lockState = CursorLockMode.None; SceneManager.LoadScene(0); } if (takeDamagePlayer.health > 0) { if (Input.GetKeyDown(KeyCode.Tab)) { bowMode = !bowMode; _animController.SetBool("isBowEquipped", bowMode); changeMode(); } if (blockDown && bowMode) { crosshair.active = true; _animController.SetBool("isAiming", true); } if (blockUp && bowMode) { GameObject.Find("Crosshair").active = false; _animController.SetBool("isAiming", false); } if (blockDown && !bowMode) { _animController.SetBool("isBlocking", true); isBlocking = true; } if (blockUp && !bowMode) { _animController.SetBool("isBlocking", false); isBlocking = false; } if (mouseClick && !bowMode) { if (slashState == SlashState.Slashing) { slashState = SlashState.Comboing; } else if (slashState == SlashState.None) { _animController.CrossFade("Slash", 0.2f); StartCoroutine(SlashRoutine()); } } if (leftShiftDown && !bowMode) { _leftShift = true; _animController.SetBool("isRunning", true); speed = _sprintSpeed; } if (leftShiftUp) { _leftShift = false; speed = _moveSpeed; } _animController.SetBool("isRunning", _leftShift); speed = _leftShift ? _sprintSpeed : _moveSpeed; Vector3 direction = transform.forward * verticalInput + Quaternion.AngleAxis(90, Vector3.up) * transform.forward * horizontalInputKeys / 1.5f; transform.Rotate(0, _turnSpeed * Time.deltaTime * horizontalInput, 0); direction.y -= _gravity * Time.deltaTime; if (!_controller.isGrounded || (slashState == SlashState.Slashing) || (!_animController.GetCurrentAnimatorStateInfo(0).IsName("Walk") && !_animController.GetCurrentAnimatorStateInfo(0).IsName("Run") && !_animController.GetCurrentAnimatorStateInfo(0).IsName("BowWalking") && !_animController.GetCurrentAnimatorStateInfo(0).IsName("Strafe") && !_animController.GetCurrentAnimatorStateInfo(0).IsName("BowAimWalking") )) { direction.x = 0f; direction.z = 0f; } _controller.Move(direction * speed * Time.deltaTime); _animController.SetBool("isWalking", Mathf.Abs(verticalInput) > 0); _animController.SetBool("isStrafing", Mathf.Abs(horizontalInputKeys) > 0); } }
IEnumerator ComboRountine() { yield return(new WaitForSeconds(0.5f)); slashState = SlashState.None; }