2D runner, need a help

I have a script for spawning platforms:

using UnityEngine;
using System.Collections;

public class SpawnScript : MonoBehaviour {

    public GameObject[] obj;
    public float spawnMin = 1f;
    public float spawnMax = 2f;

    // Use this for initialization
    void Start ()
    {
        Spawn ();
    }

    void Spawn ()
    {
        Instantiate (obj [Random.Range (0, obj.GetLength (0))], transform.position, Quaternion.identity);
        Invoke ("Spawn", Random.Range (spawnMin, spawnMax));
    }
}

But my platforms spawning or too close to each other, or on each other :frowning: What I need to do that platforms will spawn normally? Not too close to each other and not on each other.

This should work and place a game object(cube) at +8units every instance of the object. Essentially it’s placing the game object on the x plane and keeping the defaults for the y, z and rotation.

Hope it helps?

increment += 8;
int index = Random.Range (0, obj.GetLength (0));
Instantiate (obj[index], new Vector3(obj[index].transform.position.x + increment, obj[index].transform.position.y, obj[index].transform.position.z), obj[index].transform.rotation);
Invoke ("Spawn", Random.Range (spawnMin, spawnMax));