How to animate background movement in Unity

I am new to Unity. I am creating an opening screen for a 2d game and the background image is very long.
I want to animate it as if it is moving from the bottom to the top, but so far all I implemented was to modify transform.localPosition.y by substracting 0.2f each frame until it reaches the limit that i specified.
Is there a better way?

As always, it depends…

If you know the final position of your sprite, then the best way is probably MoveTowards. Let’s say the final position is stored in a Vector3 called targetPosition and your move speed is in a float called speed. In that case, you can use:

float distance = speed * Time.deltaTime;
transform.position = Vector2.MoveTowards(transform.position, target, distance);

Using transform.Translate means you have to check for when to stop but MoveTowards never goes beyond the target. Since you are multiplying by Time.DeltaTime, you’ll probably need to increase the value of speed from 0.2. Try speed = 5 and adjust…