Spawning from two different points with text

I want to spawn the obstacle exactly as per the below link.

I want exactly the same functionality of spawning obstacles with numbering. Two problems I faced: 1. I tried with two prefabs i.e. right/left with right Z position is 90 and left Z position is 60. But in this case in 02 seconds already 2 to 3 right obstacles shown on screen then left one will show 2. Unable to add increasing number functionality.

Anyone please guide me.

@faizanahmed089 You can set the correct increment values to the text by keeping the increment value in a variable and incrementing this value by one for each obstacle you spawn. I’m keeping my example very simple as I don’t know at what level you are in software. Here is the example:

private GameObject obstaclePrefabRight;

private GameObject obstaclePrefabLeft;

private int _spawnedObjectCount;
public bool IsGameOver { get; set; } = false;

public void StartSpawner(float initialDelay, float interval)
    StartCoroutine(StartSpawnerEnum(initialDelay, interval));

private IEnumerator StartSpawnerEnum(float initialDelay, float interval, bool initialCall = true)
    if (initialCall) yield return new WaitForSeconds(initialDelay);
    int positionRng = Random.Range(0, 1000);
    GameObject obstacle = Instantiate(positionRng % 2 == 0 ? obstaclePrefabRight : obstaclePrefabLeft, transform);
    obstacle.transform.localPosition =;//SET POSITION ON ROAD
    if(obstacle.TryGetComponent(out TMP_Text tmpText))
        tmpText.text = _spawnedObjectCount.ToString();

    if (IsGameOver) yield break;
    yield return new WaitForSeconds(interval);
    StartCoroutine(StartSpawnerEnum(initialDelay, interval, false));

If there are things you do not understand or want me to elaborate on, you can ask.

Increasing number functionality is really easy, just make an integer and when you spawn an obstacle you tick it up. Best to make it a static int in the script for the obsticle, then you can tick it up in the OnEnable method.