Question by
ChronoMoon · Aug 04, 2017 at 04:13 AM ·
c#objectrandom
Obstacle Spawner Efficiency
Apologies for the seemingly easy question, i am new to coding and Unity
I Have some objects being procedurally generated via a SpawnObstacles() Function, It works, however not quite how i want it to.
void SpawnObstacles () {
int randomIndex = Random.Range(0, spawnPoints.Length);
int[] test = new int[8];
test[0] = Random.Range(0, spawnPoints.Length);
test[1] = Random.Range(0, spawnPoints.Length);
test[2] = Random.Range(0, spawnPoints.Length);
test[3] = Random.Range(0, spawnPoints.Length);
test[4] = Random.Range(0, spawnPoints.Length);
test[5] = Random.Range(0, spawnPoints.Length);
test[6] = Random.Range(0, spawnPoints.Length);
test[7] = Random.Range(0, spawnPoints.Length);
for (int i = 0; i < spawnPoints.Length; i++)
{
if (randomIndex != test[i])
{
float XAxis = spawnPoints[i].position.x;
float YAxis = spawnPoints[i].position.y;
float ZAxis = spawnPoints[i].position.z;
Vector3 spawn = new Vector3(XAxis, YAxis, ZAxis); // Random.Range(0f,15f)
Instantiate(obstacle, spawn, Quaternion.identity);
}
}
I want there to always be some form of gap between the obstacles, sometimes however there is no gap and im not sure how to fix that.
Comment
Your answer
Follow this Question
Related Questions
making object move forward 0 Answers
How to make a Teleporter Pad send Player to other random Teleporter Pad? 1 Answer
Moving slowly copy of object to random position on x,z? 0 Answers
How to add force in random directions? 0 Answers
Problema al crear objeto por segunda vez. Problem to instantatiate a object for second try. 1 Answer