Example #1
0
    void FixedUpdate()
    {
        var grounded = IsGrounded();

        if (!isGrounded && grounded)
        {
            playerSfx.PlayLandSound();
        }
        isGrounded = grounded;
        if (body.transform.position.x < -19.0f)
        {
            levelController.PreviousMap();
        }
        if (body.transform.position.x > 19.0f)
        {
            levelController.NextMap();
        }

        if (grounded)
        {
            if (Input.GetKey(KeyCode.UpArrow))
            {
                body.velocity = new Vector2(body.velocity.x, jumpSpeed);
            }
        }

        if (Input.GetKey(KeyCode.R))
        {
            levelController.Reload();
        }

        if (Input.GetKey(KeyCode.RightArrow))
        {
            body.AddForce(Right(new Vector2(speed, 0), grounded));
        }

        if (Input.GetKey(KeyCode.LeftArrow))
        {
            body.AddForce(Left(new Vector2(-speed, 0), grounded));
        }

        MaxSpeed();

        if (IsMovingGrounded() && !IsPushing())
        {
            playerSfx.PlayWalk();
        }

        var spd = Mathf.Abs(body.velocity.x);

        animator.SetFloat("speed", spd);
        animator.SetFloat("speedy", body.velocity.y);
        animator.SetBool("grounded", grounded);

        if (IsPushing() && spd > 0.01f)
        {
            playerSfx.PlayShoveBox();
            animator.SetBool("pushing", true);
            render.localPosition = new Vector2(-0.6f, -0.1f);
        }
        else
        {
            animator.SetBool("pushing", false);
            render.localPosition = new Vector2(0f, -0.1f);
        }
    }