//Finds all of the empty blocks and fills them with a new randomized block void initEmptyBlocks() { //Iterate through the 2-layer array here for (int j = 0; j < colorBlockArray.GetLength(0); j++) { for (int i = 0; i < colorBlockArray.GetLength(1); i++) { if (!(colorBlockArray[j, i] != null)) { //dropBlock(Random.Range(0,dropBlockArray.Length-1), true) //ColorBlock.randomizeBlock (); colorBlock block = (colorBlock)Instantiate(ColorBlock); colorBlockArray [j, i] = block as colorBlock; blockSetIncrement(); colorBlockArray [j, i].setBlockColor(blockSet); blockSetIncrement(); //colorBlockArray [j, i].randomizeBlock(); colorBlockArray [j, i].transform.position = getArrayLocationVector3(j, i); colorBlockArray [j, i].setVecPos(getArrayLocationVector3(j, i)); colorBlockArray [j, i].setXY(j, i); colorBlockArray [j, i].setScoreCombo(false); //RemovalBlocks are the graphical removing effect. removalBlock rBlock = (removalBlock)Instantiate(RemovalSphere); rBlock.transform.position = colorBlockArray [j, i].transform.position; } } } }
//Removes a single block from the array and sets its space to null. void removeBlock(int xIndex, int yIndex) { if (xIndex >= colorBlockArray.GetLength(0) || yIndex >= colorBlockArray.GetLength(1)) { // Don't do anything if the index given is bigger than the amount of spaces in the array. } else //Otherwise //Destroy what's in the location, and then set that space to null; { if ((colorBlockArray [xIndex, yIndex] != null)) { removalBlock rBlock = (removalBlock)Instantiate(RemovalSphere); rBlock.transform.position = colorBlockArray [xIndex, yIndex].transform.position; GameObject.Destroy(colorBlockArray [xIndex, yIndex].gameObject); } colorBlockArray [xIndex, yIndex] = null; } }