示例#1
0
    //
    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();
        }
    }
示例#2
0
    public void Grab()
    {
        if (detectedObject == null)
        {
            return;
        }
        if (grabbedObject)
        {
            return;
        }
        if (grabbedJoint)
        {
            return;
        }

        grabbedObject = detectedObject;

        HeroInput grabbedInput = grabbedObject.GetComponent <HeroInput>();

        if (grabbedInput && grabbedInput.IsBlocking())
        {
            grabbedObject = null;
            return;
        }

        JamSuite.Physics2D.IgnoreCollision(grabbedObject.gameObject, cachedBody.gameObject, true);

        grabbedObject.transform.position = cachedTransform.position + Vector3.up * grabOffset;
        grabbedObject.gameObject.BroadcastMessage("PrepareForGrab", SendMessageOptions.DontRequireReceiver);

        grabbedMass        = grabbedObject.mass;
        grabbedObject.mass = grabMass;

        grabbedJoint               = gameObject.AddComponent <HingeJoint2D>();
        grabbedJoint.anchor        = new Vector2(0.0f, grabOffset);
        grabbedJoint.connectedBody = grabbedObject;
        grabbedJoint.useLimits     = true;
        grabbedJoint.limits        = new JointAngleLimits2D()
        {
            min = 0.0f, max = 0.0f
        };
    }
示例#3
0
    private void Update()
    {
        Color targetColor = cachedInput.IsBlocking() ? blockingColor : defaultColor;

        cachedRenderer.color = Color.Lerp(cachedRenderer.color, targetColor, smoothness * Time.deltaTime);
    }