Пример #1
0
    // Update is called once per frame
    void FixedUpdate()
    {
        if (!GameManager.IsPaused())
        {
            if (!WorldManager.IsWorldFuture())
            {
                grounded = Physics2D.OverlapCircle(groundCheck.position, groundRadius, WorldManager.PresentWorldLayer());
            }
            else
            {
                grounded = Physics2D.OverlapCircle(groundCheck.position, groundRadius, WorldManager.FutureWorldLayer());
            }

            animator.SetBool("Ground", grounded);
            animator.SetFloat("vSpeed", rigidbody2D.velocity.y);

            GhostPlayer.Grounded(grounded);
            GhostPlayer.VSpeed(rigidbody2D.velocity.y);

            if (grounded)
            {
                doubleJump = false;
            }

            /** Check if the player is stuck against a wall **/
            float move = Input.GetAxisRaw("Horizontal");

            if (wallHit && !grounded)
            {
                animator.SetFloat("Speed", 0f);
                GhostPlayer.Move(0f);
                rigidbody2D.velocity = new Vector2(0f, rigidbody2D.velocity.y);
            }
            else
            {
                animator.SetFloat("Speed", Mathf.Abs(move));
                GhostPlayer.Move(Mathf.Abs(move));
                rigidbody2D.velocity = new Vector2(move * maxSpeed, rigidbody2D.velocity.y);
            }

            if ((move > 0 && !facingRight) || (move < 0 && facingRight))
            {
                Flip();
            }
        }
    }
Пример #2
0
    void Update()
    {
        if (!GameManager.IsPaused())
        {
            if ((grounded || (!doubleJump && doubleJumpEnabled)) && Input.GetButtonDown("Jump"))
            {
                animator.SetBool("Ground", false);
                GhostPlayer.Grounded(false);

                rigidbody2D.AddForce(new Vector2(0, jumpForce));

                if (!doubleJump && !grounded)
                {
                    doubleJump = true;
                }
            }
        }
    }