I have 10 prefabs that are instantiated by a cube with a the following script attached to it:
public GameObject[] obj;
public float spawn = 2f;
// Use this for initialization
void Start () {
Spawn ();
}
void Update(){
transform.Translate (Vector2.up * Time.deltaTime);
}
public void Spawn(){
Instantiate (obj [Random.Range(0, obj.GetLength(0))],transform.position, Quaternion.identity);
Invoke ("Spawn", spawn);
}
}
the problem is that some prefabs get instantiated at a bigger x, like to the side, some with a negative x which spawns them to the other side causing only part of them to be seen and other is out of bounds, how do i position them all on same x?
EDIT: all of the prefabs are instantiated at x = 0, but each prefab is to be centered has different x, such as 1, 0.5, -6.3…