Increase speed every 5 seconds

Why would this not work?

    public static float speed = -5f;
    public Vector2 obstacleVelocity = new Vector2(0.0f, speed);
    public Rigidbody2D rb;

    // Use this for initialization
    void Start()
    {
        InvokeRepeating("IncreaseSpeed", 3, 1);
        rb.velocity = obstacleVelocity;
        transform.position = new Vector3(Random.Range(transform.position.x - 2.2f, 2.2f), transform.position.y + 2, transform.position.z);
    }
    
    void Update()
    {
            
        Destroy(gameObject, 5);
    }

  

    void IncreaseSpeed()
    {
        speed = speed - 5f;
    }

I know there is a number of ways to do this, but what I tried to do is assign the Y value to -5, and then icrease Y (speed) every 3 seconds for -0.3f. It doesn´t seem to work, the objects are not getting any faster.

Thanks!

you need to assign the newly calculated velocity to the rigidbody in IncreaseSpeed(). Vector2 is a value type, not a reference type, which means, the value is copied to velocity not referenced and can therefore not be “updated”.