示例#1
0
    private void FixedUpdate()
    {
        rb.AddForce(new Vector3(horizontal * speed, 0, 0));
        timeUntilNextJump -= Time.fixedDeltaTime;

        /**STATE MACHINE**/
        if (myJumpStatus == jumpStatus.runningState)
        {
            if (jump && timeUntilNextJump <= 0)
            {
                grounded = false;
                Jump();
                myJumpStatus = jumpStatus.jumpingState;
            }
        }

        if (myJumpStatus == jumpStatus.jumpingState)
        {
            if (grounded && timeUntilNextJump <= 0)
            {
                myJumpStatus      = jumpStatus.runningState;
                timeUntilNextJump = jumpCooldown;
            }
            if (!grounded)
            {
                // if falling...
                if (rb.velocity.y < 0)
                {
                    // ... fall faster like mario
                    rb.velocity += Vector3.up * Physics.gravity.y * (fallMultiplier - 1) * Time.fixedDeltaTime;
                }
                else if (rb.velocity.y > 0 && !Input.GetButton("Jump"))
                {
                    rb.velocity += Vector3.up * Physics.gravity.y * (lowJumpMultiplier - 1) * Time.fixedDeltaTime;
                }
            }
        }
    }
示例#2
0
 // Start is called before the first frame update
 void Start()
 {
     rb           = GetComponent <Rigidbody>();
     audioSource  = GetComponent <AudioSource>();
     myJumpStatus = jumpStatus.runningState;
 }