In my code i create ramdom positions and instantiate the GameObject in that position, them i make a loop to intantiate more.
The problem is that sometimes the GameObects are instantiated on top of each other. what can i do to solve that?
Thanks.
Here is the code
public GameObject cube;
public Collider plane;
int size;
int nCubes;
void Start()
{
plane = GetComponent<Collider>();
Vector3 center = plane.bounds.center;
Vector3 inicio = plane.bounds.min;
Vector3 fim = plane.bounds.max;
nCubes = Random.Range(3, 6);
for (int i = 0; i < nCubes; i++)
{
Vector3 position = new Vector3(Random.Range(inicio.x, center.x), 0, Random.Range(inicio.z, fim.z));
Instantiate(cube, position, Quaternion.identity);
}