-2
這裏是相關的代碼。我想檢查當前的產卵位置是否在最後一個產卵陣列中。如何檢查矢量3是否在矢量3數組中c#
lastSpawns
是Vector3
的數組。
//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;
}
}
此代碼甚至不會編譯。你甚至試過研究這個(例如:在搜索引擎中輸入「C#array contains」)? – UnholySheep