- Home /
 
 
               Question by 
               kiranbala003 · Mar 08, 2015 at 12:09 PM · 
                instantiatespawningoffset  
              
 
              Add an offset distance between 2 spawned objects
I am trying to make a simple 2d platformer game in unity. While doing it i have encountered a problem with spawning objects. The newly spawned objects is overlapping each other. My question is how to add an offset distance between the gameobjects. Below is the code i used for the spawning.
  public class spawnscript : MonoBehaviour {
     public GameObject[] obj;
     public float spawnMin;
     public float spawnMax;
 
     // 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));
     }
 }
 
               the game objects is having different dimensions

 
                 
                ss.png 
                (177.6 kB) 
               
 
              
               Comment
              
 
               
              Answer by HammerCar · Mar 13, 2015 at 06:24 PM
Create a new Vector3 variable, call it offset and add it to the transform.position.
Your answer