Limit looping background in 2d?

I am making 2D game. I am beginner to unity. The idea is to make the player escape from a park in limited time. I want to add zombies randomly in the park. If the player able to get out from the park in time, he will win. I want the background looping but only for 25 times. If he reach the last background, he will win. Can someone help me or give me better idea?

your post is kind of misleading, your use of the term “background”. But I can help you with the looping problem

To set this up

  1. Create your zombie GameObject and a new folder in the assets folder called "Resources" this will be used for [Resources.Load][1] and [Instantiate][2].
  2. Next drag your zombie GameObject into the Resources folder to create what is known as a prefab.
  3. Click on it so the components of the prefab show up in the inspector, on the Transform (very first) component click on the gear>Reset Position so the zombie spawns right on the spawner rather than however far away.
  4. Add the following code to a CSharp script:

SpawnerScript.cs

int loopingLeft;

int loopingTimeout;

void Awake(){
    //assign in Awake just in case
    loopingLeft = 25;
    loopingTimeout = 0;
}

void Update(){
    if(loopingTimeout == 0){
        if(loopingLeft != 0){
            //clone the zombie
            //To clone the zombie drag the original "GameObject" into a new 
            folder called "Resources" so you can access and duplicate the 
            zombie using Resources.Load the gameobject you duplicated is called a prefab. The gameObject.transform is so the zombie spawns in the spawner gameobject.
            Instantiate(Resources.Load("zombie") as GameObject, gameObject.transform);
            loopingLeft--;
            loopingTimeout = 100;
        }
    }else{
        loopingTimeout--;
    }
}

I'm more of a 3D person but for this they're the same. I hope this was helpful! Contact me if you have any questions/concerns