How can I speed up an instantiated object as time goes on?

Hi all,

I have a game where asteroid prefabs spawn at the top of the screen, but I want them to speed up over their lifetime. The script to move them is very simple.

Current code:

public class Mover : MonoBehaviour
{
    public static float speed = -5f;
    public Rigidbody rigidBody;

    void Start()
    {
        rigidBody = GetComponent<Rigidbody>();
        rigidBody.velocity = transform.forward * speed;
    }
}

Please help.

You could just simply add FixedUpdate() and add force to your rigidbody.

I would also like to ask that why is your speed static? I would guess that there are more than single meteor and all of them have that same script which will make using static pretty dangerous. In most cases you should try to avoid using statics and reference the script instead if you need to change value.