title: How to move 2D Object with WASD in Unity
body: <p>My code below only works for horizontal movement.  Shouldn't the vertical movement be working too?  I'm just starting out with basic 2D Unity programming:</p>
  
  <pre><code>public class Player : MonoBehaviour {
  
      //These fields will be exposed to Unity so the dev can set the parameters there
      [SerializeField] private float speed = 1f;
      [SerializeField] private float upY;
      [SerializeField] private float downY;
      [SerializeField] private float leftX;
      [SerializeField] private float rightX;
  
      private Transform _transformY;
      private Transform _transformX;
      private Vector2 _currentPosY;
      private Vector2 _currentPosX;
  
      // Use this for initialization
      void Start () {
          _transformY = gameObject.GetComponent&lt;Transform&gt; ();
          _currentPosY = _transformY.position;        
  
          _transformX = gameObject.GetComponent&lt;Transform&gt; ();
          _currentPosX = _transformX.position;
      }
  
      // Update is called once per frame
      void Update () {
          _currentPosY = _transformY.position;
          _currentPosX = _transformX.position;
  
          float userInputV = Input.GetAxis ("Vertical");
          float userInputH = Input.GetAxis ("Horizontal");
  
          if (userInputV &lt; 0) 
              _currentPosY -= new Vector2 (0, speed);     
  
          if (userInputV &gt; 0)
              _currentPosY += new Vector2 (0, speed);
  
          if (userInputH &lt; 0)
              _currentPosX -= new Vector2 (speed, 0);
  
          if (userInputH &gt; 0)
              _currentPosX += new Vector2 (speed, 0);
  
          CheckBoundary ();
  
          _transformY.position = _currentPosY;
          _transformX.position = _currentPosX;
      }
  
      private void CheckBoundary(){
          if (_currentPosY.y &lt; upY)
              _currentPosY.y = upY;
  
          if (_currentPosY.y &gt; downY)
              _currentPosY.y = downY;
  
          if (_currentPosX.x &lt; leftX)
              _currentPosX.x = leftX;
  
          if (_currentPosX.x &gt; rightX)
              _currentPosX.x = rightX;
      }
  }
  </code></pre>
  
  <p>If I remove/comment out the <code>_currentPosX</code> and it's related codes then my Vertical movement works.  But if I remove/comment out the <code>_currentPosY</code> and it's related codes then my Horizontal movement works.</p>
  
  <p>But how come I'm having trouble getting them to work at the same time?  I think I'm just missing something but I can't figure it out since I'm just a beginner at this.</p>
  
  <p>Thanks to whoever can give advise.</p>
  
  <p>EDIT:  for further clarification...</p>
  
  <p>I'm coding a simple 2d game that will have the player move in 4-directions using the WASD keys.</p>
  
  <pre><code>W = move up
  A = move left
  S = move down
  D = move right
  </code></pre>
  
  <p>My main problem is that I can get two of the keys working only in one axis: either A and D is working for Horizontal while W and S are not working at all for Vertical movement or vice-versa.</p>