changing position.y based on a float variable..

So… this is another very newbie programming question. I’m trying to set the position.y of a gameobject to equal to transform.position.y + x, x being a float number that changes based on the speed of a different gameobject in the scene. the basic problem is that it seems like whatever I do, adding a number to the transform.position.y in update will add it every frame… my question is how can I add a number to a position axis of an object that doesn’t add, but updates the addition value of the position.y+x… I hope this makes sense… here’s my epic fail code so far:

    void Update()
    {
        transform.position = new Vector3(transform.position.x, test(), transform.position.z);
    }

    float test() 
    {
        float newPos = transform.position.x + speed;
        return newPos;
    }

You could do it over time by

test() * Time.deltaTime

or you could use a var like ‘nextOffset’ and set that to test() where ever, then to zero after you actually add it.

But why do it in Update unless you want to keep adding it over time? If it’s a one-time thing, do it in the function that triggers such behavior.