How to move my 2D player up or down on the vertical axes depending on if it is facing up or down?

Below is my code that currently rotates the character:

if (Input.GetKey(KeyCode.RightArrow))
        {
            transform.Rotate (Vector3.back);
        }

        if (Input.GetKey(KeyCode.LeftArrow))
        {
            transform.Rotate (Vector3.forward);
        }

Basically, I got the player moving up, down, left and right to start with.

Then I got the player to be able to rotate.

I then deleted the original movement part of my code, as I just want the player to be able to move up or down on the vertical axis, depending on whether it is facing the up or down direction.

Can anyone help me with this?

Cheers in advance dudes!

Instead of using Vector3, use Vector2. Next, you’ll want to specify if they press the UpArrow or DownArrow, like this…

 void Update()
    {
      if (Input.GetKey(KeyCode.UpArrow))
        {
             Transform.Translate (0, speed,0);
        }
    }

If you are using a rigidbody2D, then you could do an AddForce such as…

void Update()
        {
          if (Input.GetKey(KeyCode.UpArrow))
            {
                 rb2d.AddForce(transform.up * speed);
            }
        }