2D How to move object only to the up

Hello I want to move object always to the up how can I do this can someone give me example code? (I’m beginner)

I don’t know how you want to do it , so I will give you some example code:

transform.Translate(Vector3.up * speed * Time.deltaTime);

if you place this script in an update method, your gameObject will go indefinitely upwards.

But, if you want something that works with physics, you can use:

 public Rigidbody2D rb2D;

 void Start()
    {
        rb2D = GetComponent.<Rigidbody2D>();
    }

 void Update()
    {
        rb2D.velocity = Vector2.up * speed * Time.deltaTime;
    }

You can notice that in each proposition, there is a speed value. You can create a public float speed to set to whatever you want the speed at which your object will move upwards.