Ejemplo n.º 1
0
 void UpMove()
 {
     if (CanMoveUp == true)
     {
         state = MoveingState.up;
         playerRigidbody.transform.Translate(new Vector3(0, 0, 1) * moveSpeed * Time.deltaTime);
     }
 }
Ejemplo n.º 2
0
 void DownMove()
 {
     if (CanMoveDown == true)
     {
         state = MoveingState.down;
         playerRigidbody.transform.Translate(new Vector3(0, 0, -1) * moveSpeed * Time.deltaTime);
     }
 }
Ejemplo n.º 3
0
 void LeftMove()
 {
     if (CanMoveLeft == true)
     {
         state = MoveingState.left;
         playerRigidbody.transform.Translate(new Vector3(-1, 0, 0) * moveSpeed * Time.deltaTime);
     }
 }
Ejemplo n.º 4
0
 void RightMove()
 {
     if (CanMoveRight == true)
     {
         state = MoveingState.right;
         playerRigidbody.transform.Translate(new Vector3(1, 0, 0) * moveSpeed * Time.deltaTime);
     }
 }
Ejemplo n.º 5
0
 void Start()
 {
     playerRigidbody = GetComponent <Rigidbody>();
     CanMoveRight    = true;
     CanMoveLeft     = true;
     CanMoveDown     = true;
     CanMoveUp       = true;
     state           = MoveingState.stop;
 }
Ejemplo n.º 6
0
    void FixedUpdate()
    {
        #region PressKey
        if (state == MoveingState.stop)
        {
            //Right
            if (Input.GetKey(KeyCode.RightArrow))
            {
                //if (!MoveRight )
                if (CanMoveRight)
                {
                    MoveRight = true;
                }
            }


            //Left
            if (Input.GetKey(KeyCode.LeftArrow))
            {
                //if (!MoveLeft)
                if (CanMoveLeft)
                {
                    MoveLeft = true;
                }
            }


            //Down
            if (Input.GetKey(KeyCode.DownArrow))
            {
                //if (!MoveDown)
                if (CanMoveDown)
                {
                    MoveDown = true;
                }
            }


            //Up
            if (Input.GetKey(KeyCode.UpArrow))
            {
                //if (!MoveUp)
                if (CanMoveUp)
                {
                    MoveUp = true;

                    /*CanMoveRight = true;
                     * MoveRight = false;
                     * CanMoveLeft = true;
                     * MoveLeft = false;
                     * CanMoveDown = true;
                     * MoveDown = false;*/
                }
            }
        }
        #endregion PressKey

        if (MoveRight)
        {
            RightMove();
        }
        else if (MoveUp)
        {
            UpMove();
        }
        else if (MoveDown)
        {
            DownMove();
        }
        else if (MoveLeft)
        {
            LeftMove();
        }
        else
        {
            state = MoveingState.stop;
        }
    }