- Home /
Cycle Through Array - Change Values
Hello,
I'm trying to get a wall of cubes to 'SetActive' either on or off.
Right now, I am able to use the 'CreatePrimitive' to build a column of cubes, I then have a while loop to either turn them off or on (random).
What I want to do, is to have an entire wall doing this too. I have a feeling I might need to mess around with 2d arrays?
var cubeIndex : int = 0;
var cubes_X : GameObject[];
var cubes_Y : GameObject[];
function Start () {
for (var y = 0; y < 10; y++) {
var cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
cube.AddComponent(Rigidbody);
cube.transform.position = Vector3 (0, y, 0);
cube.transform.name = "0_Cube_" + y;
cube.SetActive(false);
cubes_Y[y] = cube;
}
//Either turns the lower cube off, or the upper cube on
while(true){
var AddOrTake = Random.Range(0, 2);
if(AddOrTake == 0 && cubeIndex < cubes_Y.length - 1){
cubes_Y[cubeIndex].SetActive(true);
cubeIndex++;
}
else if(AddOrTake == 0 && cubeIndex == cubes_Y.length){
cubeIndex--;
cubes_Y[cubeIndex].SetActive(false);
}
else if(AddOrTake == 1 && cubeIndex > 0){
cubeIndex--;
cubes_Y[cubeIndex].SetActive(false);
}
else{
cubes_Y[cubeIndex].SetActive(true);
cubeIndex++;
}
yield WaitForSeconds(0.1);
}
}
So what it does, is starts from the ground up, and either turns on the cube, or turn off the lower cube every 0.1 seconds - so really, the column is either randomly growing, or shrinking.
Now what I want, is to have a wall (instead of just a column) to do the same.
Thanks
Your answer
Follow this Question
Related Questions
Move one vertice of my cube 1 Answer
Creating multiple faces (cubes) 1 Answer
How do I curve a cube? 1 Answer
Cannot Instantiate to the right position 1 Answer
Cube glitches when it moves into wall 2 Answers