// private void Update() { if (health == 0) { return; } // recovery if (isStunned) { currentRecoveryTime = Mathf.Min(currentRecoveryTime + Time.deltaTime, recoveryInterval); } // stabilization if (stabilize) { cachedTransform.rotation = Quaternion.Slerp( cachedTransform.rotation, stableRotation, stabilizationSmoothness * Time.deltaTime ); } // cooldown currentCooldownTime = Mathf.Max(0, currentCooldownTime - Time.deltaTime); // regain stamina if (Mathf.Abs(currentCooldownTime) < Mathf.Epsilon) { stamina = Mathf.Min(stamina + staminaRegainSpeed * Time.deltaTime, maxStamina); } // take stamina constantly if we're blocking if (cachedInput.IsBlocking()) { stamina = Mathf.Max(0, stamina - staminaLossInBlock * Time.deltaTime); } // take stamina constantly if we're carrying an object in our hands Rigidbody2D obj = cachedHands.GetGrabbedObject(); if (obj) { currentCooldownTime = staminaCooldown; stamina = Mathf.Max(0, stamina - staminaLossMultiplier * obj.mass * Time.deltaTime); } // drop carrying object if we're weak if (Mathf.Abs(stamina) < Mathf.Epsilon) { cachedHands.Drop(); } }
// private void Update() { if (cachedBody == null) { return; } if (cachedHands == null) { return; } // recovery if (Input.GetButtonDown(jump) && cachedHero.CanRecover()) { cachedHero.RestoreAfterLanding(); } if (isGrabbed) { return; } // movement float input = Input.GetAxis(moveHorizontal); isMoving = Mathf.Abs(input) > Mathf.Epsilon; cachedBody.velocity = new Vector2(input * moveVelocity, cachedBody.velocity.y); // orient if (isMoving) { cachedTransform.localScale = new Vector3(Mathf.Sign(input), 1.0f, 1.0f); } // block if (Input.GetButtonDown(block)) { isBlocking = true; } if (Input.GetButtonUp(block)) { isBlocking = false; } if (Mathf.Abs(cachedHero.stamina) < Mathf.Epsilon) { isBlocking = false; } // jump if (Input.GetButtonDown(jump) && !cachedCollision.InAir()) { cachedBody.velocity = cachedBody.velocity.WithY(jumpVelocity); cachedCollision.SetInAir(true); currentJumps = 0; } if (Input.GetButtonDown(jump) && cachedCollision.InAir() && (currentJumps < maxJumps)) { cachedBody.velocity = cachedBody.velocity.WithY(jumpVelocity); currentJumps++; } // grab if (isBlocking) { cachedHands.Drop(); } else { if (Input.GetButtonDown(grab)) { cachedHands.Grab(); } if (Input.GetButtonUp(grab)) { cachedHands.Drop(throwStrength, throwVertical); } } }