示例#1
0
    void PlayerMovement()
    {
        ////MOVEMENT////
        //Positive oder Negative Axis wird gespeichert von dem Horizontal input //GetAxisRaw -1 or 1
        moveHorizontal = Input.GetAxisRaw("Horizontal");
        //Positive oder Negative Axis wird gespeichert von dem Vertical input //GetAxisRaw -1 or 1
        moveVertical = Input.GetAxisRaw("Vertical");

        #region Anim DIRECTION
        //if (moveHorizontal < 0)
        //    playAnimation.Left();
        //if (moveHorizontal > 0)
        //    playAnimation.Right();
        //if (moveVertical > 0)
        //    playAnimation.Up();
        //if (moveVertical < 0)
        //    playAnimation.Down();

        //if (moveHorizontal < 0 && moveVertical < 0)
        //    playAnimation.RightUp();

        //if (moveHorizontal < 0 && moveVertical > 0)
        //    playAnimation.LeftUp();

        //if (moveHorizontal > 0 && moveVertical < 0)
        //    playAnimation.RightDown();

        //if (moveHorizontal > 0 && moveVertical > 0)
        //    playAnimation.LeftDown();

        #endregion

        if (moveHorizontal != 0 || moveVertical != 0)
        {
            moving = true;
        }
        else
        {
            moving = !moving;
        }

        if (!moving)
        {
            #region Anim WASD DIRECTION

            Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            mousePos.z = 0;

            //need this for Fire Rain
            //gameObject.transform.position = mousePos;
            //targetRotation = Quaternion.LookRotation(mousePos);
            // transform.eulerAngles = Vector3.up * Mathf.MoveTowardsAngle(transform.eulerAngles.y, targetRotation.eulerAngles.y, rotationSpeed * Time.deltaTime);

            //Debug.DrawRay(transform.position, Vector3.forward, Color.red);

            if (mousePos.x < (gameObject.transform.position.x + 0.53F) && mousePos.x > (gameObject.transform.position.x - 0.53F) && mousePos.y < gameObject.transform.position.y)
            {
                playAnimation.Down();
            }

            if (mousePos.x < (gameObject.transform.position.x + 0.53F) && mousePos.x > (gameObject.transform.position.x - 0.53F) && mousePos.y > gameObject.transform.position.y)
            {
                playAnimation.Up();
            }

            if (mousePos.y < (gameObject.transform.position.y + 0.53F) && mousePos.y > (gameObject.transform.position.y - 0.49F) && mousePos.x < gameObject.transform.position.x)
            {
                playAnimation.Left();
            }

            if (mousePos.y < (gameObject.transform.position.y + 0.53F) && mousePos.y > (gameObject.transform.position.y - 0.49F) && mousePos.x > gameObject.transform.position.x)
            {
                playAnimation.Right();
            }

            if (mousePos.x > (gameObject.transform.position.x + 0.54F) && mousePos.y > (gameObject.transform.position.y + 0.54F))
            {
                playAnimation.RightUp();
            }

            if (mousePos.x > (gameObject.transform.position.x + 0.54F) && mousePos.y < (gameObject.transform.position.y - 0.54F))
            {
                playAnimation.RightDown();
            }

            if (mousePos.x < (gameObject.transform.position.x - 0.54F) && mousePos.y > (gameObject.transform.position.y + 0.54F))
            {
                playAnimation.LeftUp();
            }

            if (mousePos.x < (gameObject.transform.position.x - 0.54F) && mousePos.y < (gameObject.transform.position.y - 0.54F))
            {
                playAnimation.LeftDown();
            }
            #endregion
        }

        PlayerRun(disableMovement);
    }