Beispiel #1
0
    // Update is called once per frame
    void Update()
    {
        resetState();
        if (Canvases != null)
        {
            foreach (GameObject canv in Canvases)
            {
                if (canv.activeSelf)
                {
                    canMove = false;
                }
            }
        }

        //Check if the player can move and is registering input
        if (canMove)
        {
            movement.x = uControls.Player.MovePlayer.ReadValue <Vector2>().x; //Input.GetAxisRaw("Horizontal");
            movement.y = uControls.Player.MovePlayer.ReadValue <Vector2>().y; //Input.GetAxisRaw("Vertical");
        }
        else
        {
            movement.x = 0;
            movement.y = 0;
        }

        #region Depreciated_mouse_control

        /*
         * /////////////////////////////////////////////////////////////////////////////////////////////////////////////////// testing here
         * if (Input.GetMouseButtonDown(0) == true && RightLeg == true && canMove == true)
         * {
         *  RightLeg = false;
         *  LeftLeg = true;
         *  countTime = CheckSpeed(countTime);
         *   if (movement.x == 1 && canMoveRight == true) //going right
         *   {
         *       GotoNumberX(rb.position + movement * moveSpeed, canMove);
         *   }
         *   if (movement.x == -1 && canMoveLeft == true) //going left
         *   {
         *       GotoNumberX(rb.position + movement * moveSpeed, canMove);
         *   }
         *   if (movement.y == 1 && canMoveUp == true) //going up
         *   {
         *       GotoNumberY(rb.position + movement * moveSpeed, canMove);
         *   }
         *   if (movement.y == -1 && canMoveDown == true) //going down
         *   {
         *       GotoNumberY(rb.position + movement * moveSpeed, canMove);
         *   }
         *  rb.MovePosition(rb.position + movement * moveSpeed * Time.fixedDeltaTime);
         * }
         * if (Input.GetMouseButtonDown(1) == true && LeftLeg == true && canMove == true)
         * {
         *  RightLeg = true;
         *  LeftLeg = false;
         *  if (movement.x == 1 && canMoveRight == true) //going right
         *  {
         *      GotoNumberX(rb.position + movement * moveSpeed, canMove);
         *  }
         *  if (movement.x == -1 && canMoveLeft == true) //going left
         *  {
         *      GotoNumberX(rb.position + movement * moveSpeed, canMove);
         *  }
         *  if (movement.y == 1 && canMoveUp == true) //going up
         *  {
         *      GotoNumberY(rb.position + movement * moveSpeed, canMove);
         *  }
         *  if (movement.y == -1 && canMoveDown == true) //going down
         *  {
         *      GotoNumberY(rb.position + movement * moveSpeed, canMove);
         *  }
         *  rb.MovePosition(rb.position + movement * moveSpeed * Time.fixedDeltaTime);
         * }
         * ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
         */
        #endregion

        //Check the states for the walk animation.
        #region ChecKWalkStates

        if (movement.x != 0 && movement.y != 0)
        {
            if (movement.x < 0)
            {
                anim.SetBool("walkingLeft", true);
            }

            if (movement.x > 0)
            {
                anim.SetBool("walkingRight", true);
            }
        }
        else
        {
            if (movement.x != 0)
            {
                if (movement.x < 0)
                {
                    anim.SetBool("walkingLeft", true);
                }

                if (movement.x > 0)
                {
                    anim.SetBool("walkingRight", true);
                }
            }

            if (movement.y != 0)
            {
                if (movement.y < 0)
                {
                    anim.SetBool("walkingForwards", true);
                }

                if (movement.y > 0)
                {
                    anim.SetBool("walkingBackwards", true);
                }
            }
        }
        #endregion

        if (movement.x != 0 || movement.y != 0)
        {
            walking = true;
        }
        else
        {
            walking = false;
        }

        if (walking && !isPlaying && manager != null && myRoom.getName() != "Outside" && !InvCanvas.activeSelf && !Journal.activeSelf && canMove)
        {
            manager.Play("Player Footsteps", true);
            isPlaying = true;
        }
        if (walking && !isPlaying && manager != null && myRoom.getName() == "Outside" && !InvCanvas.activeSelf && !Journal.activeSelf && canMove)
        {
            manager.Play("Snow Footsteps", true);
            isPlaying = true;
        }
        else
        {
            isPlaying = false;
        }
    }