Esempio n. 1
0
    //only called when finger comes off screen
    void ProcessSlingshot()
    {
        Vector2 slingVector      = GetCurrentSlingVector();
        Vector2 slingVectorThrow = GetVectorToThrow();

        if (staminaBar.GetCurrentStamina() > 0 && !hasBeenSlung)
        {
            Vector3 forceAdded = slingVectorThrow.normalized * slingVector.magnitude * slingSpeed;
            float   forceAddedMagnitudeClamped = Mathf.Clamp(forceAdded.magnitude, minForceToApply, maxForceToApply);

            //calculates total force to apply, taking into account the magnitude the player requested, along with current stamina
            float forceCalculationWithCurrentStamina = GetClampedForceToApply(forceAddedMagnitudeClamped);

            rigidBody.AddForce(forceAdded.normalized * forceCalculationWithCurrentStamina);
            hasBeenSlung = true;
            StartCoroutine(WaitForNextSling());
        }

        //set currentMaxMagnitude to the lastSlingVector's magnitude
        ProcessReturnOfArrowData(slingVector);
    }