Esempio n. 1
0
        // Get the current speed for the player.
        public float GetSpeed(bool withPlatform = true)
        {
            // Cache the horizontal input, run input and speed.
            bool  running;
            float speed;

            if (alwaysRunning)
            {
                running = true;
                speed   = 0f;
            }
            else
            {
                running = Input.GetButton("Run");
                speed   = runSpeed;
            }

            // If a button needs to be pressed to run...
            if (pressToRun)
            {
                // If the player is in the air and can't change between walking and running in the air...
                if (!player.grounded && !player.CanWalkAndRunInAir())
                {
                    // ... set the speed based on if the player was walking or running before jumping.
                    speed = player.AirWalk() ? walkSpeed : runSpeed;
                }
                else
                {
                    // ... set the speed to walking or running, depending on the run input.
                    speed = running ? runSpeed : walkSpeed;
                }
            }

            // If the player is crouching...
            if (player.crouching)
            {
                // ... set the speed to the crouch speed.
                speed = player.GetCrouchSpeed();
            }

            // Set the player's speed based on the speed of the platform.
            if (withPlatform)
            {
                speed = player.GetSpeedOnMovingPlatform(speed);
            }

            // Get the player's air movement speed.
            speed = player.GetSpeedInAir(speed);

            // Return the speed.
            return(speed);
        }