- Home /
Question by
Luke2 · Aug 13, 2017 at 02:45 PM ·
c#arrayvector3generation
How to check if a vector 3 is in a vector 3 array c#.
Here is the relevant code. I want to check if the current spawn location is in the last spawns array. Thank you for your help.
//Generate Level
while(cubeSpawns != 100)
{
currentSpawnLocation = new Vector3(Random.Range(-5, 5), Random.Range(-5, 5), Random.Range(-5, 5));
if (currentSpawnLocation != lastSpawns)
{
GameObject cubeClone = (GameObject)Instantiate(Cubes[Random.Range(0,Cubes.Length)], transform.position + currentSpawnLocation, Quaternion.identity);
currentSpawnLocation = lastSpawns[cubeSpawns];
cubeClone.transform.parent = CubeClones;
cubeSpawns = cubeSpawns + 1;
}
}
Comment
Best Answer
Answer by ShadyProductions · Aug 13, 2017 at 03:12 PM
if (!lastSpawns.Contains(currentSpawnLocation)) {
}
You might have to add using System.Linq;
to the top of your script.
However now I get an error that says array index is out of range.
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
How to call a function with Vector3[] argument? 3 Answers
C#-XMLSerialize a Struct with Vector3 Array in it 2 Answers
Im misunderstanding arrays. 1 Answer
C# Convert Vector3[] to Vector2[] 3 Answers