示例#1
0
 void DetectDirection()
 {
     if (Mathf.Abs(startPosition.x - endPosition.x) > Mathf.Abs(startPosition.y - endPosition.y))
     {
         if (startPosition.x > endPosition.x)
         {
             playerMovement.SetDirection(Vector2.left);
         }
         else
         {
             playerMovement.SetDirection(Vector2.right);
         }
     }
     else
     {
         if (startPosition.y > endPosition.y)
         {
             playerMovement.SetDirection(Vector2.down);
         }
         else
         {
             playerMovement.SetDirection(Vector2.up);
         }
     }
 }
示例#2
0
 private void Update()
 {
     if (Input.GetKeyDown(KeyCode.LeftArrow))
     {
         movement.SetDirection(Vector2.left);
     }
     if (Input.GetKeyDown(KeyCode.DownArrow))
     {
         movement.SetDirection(Vector2.down);
     }
     if (Input.GetKeyDown(KeyCode.RightArrow))
     {
         movement.SetDirection(Vector2.right);
     }
     if (Input.GetKeyDown(KeyCode.UpArrow))
     {
         movement.SetDirection(Vector2.up);
     }
 }