Can you trigger/run code from a unspawned objcts, that isnt in the scene yet?

Hey!

I´am working on a game, where things get faster over time (the BG and the Obsticals, the player is just moving right and left). I have a Code for my BG and My Obsticals:
__ Obstical: __

public float obsticalspeed = 2.0f;

private void Start()
{
    
}

void Update()
{
    float y = transform.position.y;

    y = transform.position.y - obsticalspeed * Time.deltaTime;

    transform.position = new UnityEngine.Vector2(transform.position.x, y);

    obsticalspeed += 0.1f * Time.unscaledDeltaTime;

}

__ BG: __

public float speed = 2.0f;

// Update is called once per frame
void Update()
{
    float y = transform.position.y;

    y = transform.position.y - speed * Time.deltaTime;

    transform.position = new UnityEngine.Vector2(transform.position.x, y);

    if(transform.position.y <= -10f)
    {
        transform.position = new UnityEngine.Vector2(0, 9.94f);
    }

    speed += 0.1f * Time.unscaledDeltaTime;
    
}

The Problem is, that the obsticals will only start to higher their speed, when they are spawned (each does that seperatly, so all obsticals will only start higering their speed, when they are spawned), so they wont have the same speed as the BG, because the BG stays the gameobject in the see and will only be teleported to the right position.

How could you fix that?
maybe start the script for every object that will be spawned in the future, so they can start counting up, when the scene starts?

if the speed should be shared you could simply access the BG speed from the other script, but you could also make the variable static

public static float speed = 2.0;

Hey!

Thanks for the very quick answer, but how do i access the other script?

I have never used the GetComponent stuff before

Thanks!

Sorry, i really dont know what you mean?
In which script and what should i drag and drop in where?

Edit: Problemsolving in the replys under this comment