private void Update() { Vector3 velocity = cachedBody.velocity; cachedAnimation.SetFloat("VelocityY", velocity.y); cachedAnimation.SetFloat("Grabbing", cachedHands.GetGrabbedObject() ? 1.0f : 0.0f); cachedAnimation.SetBool("InAir", cachedCollision.InAir()); cachedAnimation.SetBool("Moving", cachedInput.IsMoving()); cachedAnimation.SetBool("Stunned", cachedHero.IsStunned()); }
// 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(); } }