Making an object move non stop after button input?

Hello, I’m pretty new to unity and I’m trying to make an app game.

What I’m having trouble with right now, is I want the player object to move to the right without stopping when the space bar is pressed (or when the screen is touched when I port it to mobile). At the moment I can make it move when I hold down the space bar, but I want it to move constantly after one input without stopping.

Here is my code for movement:

{

public float _speed;

public float movementSpeed = 5.0f;

// Start is called before the first frame update
void Start()
{
    transform.position = new Vector3(-2.03f, 0, 6f);
}

// Update is called once per frame
void Update()
{
    if (Input.GetKeyDown(KeyCode.DownArrow))
    {
        Vector3 position = this.transform.position;
        position.y--;
        this.transform.position = position;
    }

    if (Input.GetKeyDown(KeyCode.UpArrow))
    {
        Vector3 position = this.transform.position;
        position.y++;
        this.transform.position = position;
    }

    if(Input.GetKey(KeyCode.Space))
    {
        transform.Translate(Vector3.right * Time.deltaTime);

    }
    
    if (transform.position.y >= 5f)
    {
        transform.position = new Vector3(transform.position.x, 4f, 6f);
    }

    if (transform.position.y <= -5f)
    {
        transform.position = new Vector3(transform.position.x, -4f, 6f);
    }

}

Try this…

     bool MoveRight=false; 
     ^^^Put this line at the top of your script, right after  public float movementSpeed = 5.0f;

     if(Input.GetKeyDown(KeyCode.Space))
     {
         MoveRight = !MoveRight;
     }
     if(MoveRight)
         transform.Translate(Vector3.right * Time.deltaTime);

This will start your object moving to the right when the key is pressed. It will continue moving until you press the key again. If you don’t want them to be able to stop the movement once started, change the MoveRight = !MoveRight; to MoveRight = true;

Hope this helps,
-Larry