public void SetDirection(Vector3 start, Vector3 end)
    {
        float xDifferent;
        float yDifferent;

        xDifferent = end.x - start.x;
        yDifferent = end.y - start.y;

        if (Mathf.Abs(xDifferent) > Mathf.Abs(yDifferent))
        {
            if (xDifferent > 0)
            {
                Debug.Log("Right");
                player.Move(Vector3.right);
            }
            else
            {
                Debug.Log("Left");
                player.Move(Vector3.left);
            }
        }
        else
        {
            if (yDifferent > 0)
            {
                Debug.Log("UP");
                player.Move(Vector3.forward);
            }
            else
            {
                Debug.Log("Down");
                player.Move(Vector3.back);
            }
        }
    }
Ejemplo n.º 2
0
 void Update()
 {
     if (Input.GetKeyDown(KeyCode.D))
     {
         player.Move(Vector3.right);
     }
     if (Input.GetKeyDown(KeyCode.A))
     {
         player.Move(Vector3.left);
     }
     if (Input.GetKeyDown(KeyCode.W))
     {
         player.Move(Vector3.forward);
     }
     if (Input.GetKeyDown(KeyCode.S))
     {
         player.Move(Vector3.back);
     }
 }