IEnumerator StartPunching() { _isInCooldown = true; ControlLock.Lock("MoveOnGround"); _anim.SetBool("isBunch", true); _anim.SetBool("isBunchOne", _isOne); var bunchName = string.Empty; var bunchLength = 0f; if (_anim.GetBool("isWallSliding")) { bunchName = "Wall Punch"; bunchLength = Utility.GetAnimationLength(_anim, bunchName); } else { bunchName = string.Format("Normal Bunch {0} {1}", _faceX < 0 ? "Left" : "Right", _isOne ? 1 : 2); bunchLength = Utility.GetAnimationLength(_anim, bunchName); } InstantiateEffect(); if (!_anim.GetBool("isWallSliding")) { _isOne = !_isOne; } yield return(new WaitForSeconds(bunchLength)); _anim.SetBool("isBunch", false); _isInCooldown = false; ControlLock.ReleaseLock("MoveOnGround", "Move"); }
void SetWallSlidingState() { var isWallSlidingState = IsWallSlidingState(); _anim.SetBool("isWallSliding", isWallSlidingState); if (isWallSlidingState) { _extraJump = extraJumpCount; // Flip when sliding if (!_flippedByWallSliding) { ControlLock.Lock("FlipX"); _flippedByWallSliding = true; _sprite.flipX = true; } } else { if (_flippedByWallSliding) { ControlLock.ReleaseLock("FlipX"); _flippedByWallSliding = false; _sprite.flipX = false; } } }
void ForceForJump() { if (_lockJump) { return; } if (!_player.isJump) { return; } // when jumping, the gravity value is not zero _rb.gravityScale = _player.gravity; if (!_isOnGround && _extraJump > 0) { ControlLock.ReleaseLock("Move"); StateHandling.Handle("KickDown", "Off"); _rb.velocity = new Vector2(_rb.velocity.x, jumpForce); _extraJump--; } else if (_extraJump <= 0 && _jumpByWall) { _rb.velocity = new Vector2(_rb.velocity.x, jumpForce); //Vector2.up * jumpForce; } else if (_isOnGround) { ControlLock.ReleaseLock("Move"); _anim.SetBool("isKickDown", false); _rb.velocity = new Vector2(_rb.velocity.x, jumpForce); //Vector2.up * jumpForce; } }
IEnumerator DoReflectiveForce() { ControlLock.Lock("Move"); var vel = _rb.velocity; vel.x -= .5f * _faceX; _rb.velocity = vel; yield return(new WaitForSeconds(.1f)); ControlLock.ReleaseLock("Move"); }
void OnDetectedHit(HitDetector detector, Collider2D other) { if ("Ground".Equals(LayerMask.LayerToName(other.gameObject.layer))) { _anim.SetBool("isOnGround", true); // Shake the screen when character kicks on ground. StartCoroutine(Utility.Shaking2D(_shakingDuration, _shakingAmount, _theCamera.transform , () => ControlLock.Lock("Camera1") , () => ControlLock.ReleaseLock("Camera1"))); } HandleState("KickDown", "Off"); }
IEnumerator StartPunchUp() { _isInCooldown = true; ControlLock.Lock("Move"); _anim.SetBool("isPunchUp", true); var length = Utility.GetAnimationLength(_anim, "Punch Up"); var fx = InstantiateEffect(); var fxAnim = fx.GetComponent <Animator>(); var fxLength = fxAnim.GetCurrentAnimatorStateInfo(0).length; Destroy(fx.gameObject, fxLength); yield return(new WaitForSeconds(length)); _isInCooldown = false; ControlLock.ReleaseLock("Move"); _anim.SetBool("isPunchUp", false); }
public void HandleState(string name, string state) { if (name == "KickDown") { if (state == "Off") { if (_curFx != null || _curFx is Object && !_curFx.Equals(null)) { ControlLock.ReleaseLock("Move"); _anim.SetBool("isKickDown", false); _isInCooldown = false; _rb.velocity = Vector2.zero; Destroy(_curFx.gameObject); } } } }
public override void Update() { base.Update(); if (_lockThis) { return; } if ((_player.isFrontCollision && _player.GetInputX() != 0) && !_anim.GetBool("isOnGround")) { ControlLock.Lock("Move"); if (_rb.velocity.y < 0) { _rb.velocity += Vector2.up * frictionY; } } else { ControlLock.ReleaseLock("Move"); } }
public override void Update() { if (_player.GetInputY() != 0) { if (!_firstInput) { _firstInput = true; _start = Time.time; return; } if (!_handled) { if (_start + _holdIn <= Time.time) { ControlLock.Lock("Camera"); var edge = Utility.CameraBoundEdge(_theCamera, _bound, _theCamera.transform.position); if (edge.y == 0 && _player.GetInputY() == 1) { return; } else if (edge.y == 1 && _player.GetInputY() == -1) { return; } StartCoroutine(Looking(_player.GetInputY())); _handled = true; } } } else { _firstInput = false; _handled = false; _start = 0f; ControlLock.ReleaseLock("Camera"); } }
IEnumerator StartDashing() { var percent = 0f; while (percent <= 1f) { percent += Time.deltaTime / _timeDirection; yield return(null); } _isInCooldown = true; ControlLock.Lock("Move", "FlipX", "NormalPunch", "Jump", "KickDown"); _rb.gravityScale = .0f; _isDashing = true; _anim.SetBool("isDashing", true); var length = Utility.GetAnimationLength(_anim, "Dashing Right"); _rb.velocity = Vector2.right * transform.localScale.x * dashingForce; yield return(new WaitForSeconds(length)); _isDashing = false; _anim.SetBool("isDashing", false); _rb.gravityScale = _player.gravity; ControlLock.ReleaseLock("Move", "FlipX", "NormalPunch", "Jump", "KickDown"); }