I’ve been trying to figure out how to make the code we learned for counting the amount of blocks in the scene work with how I’ve set up my game. Instead of it being a scene for each level I have the scene move up to the next level in the same scene (like an elevator). The problem with the method as is, is that it’ll count any blocks placed in the upper levels so the script that moves the playfield to the next level never gets called. I’ve explored trying to test if the object is within the camera view point, visibility checked in relation to the Y value of the camera or trying to multidimensional arrays to get the script to read each set of blocks as separate sets. Not sure where I should be headed for a solution for this.
Original code for counting blocks in the scene.
if (!isUnbreakable)
{
getCount = GameObject.FindGameObjectsWithTag (“Block”);
coinCount = getCount.Length;
Debug.Log ("Coin count is: " + coinCount);
}
How can I use a foreach loop or some other method to count according to a variable (the set of blocks corresponding level)? I tried using if statements and an array for the block count with the level variable but it still counts all of the blocks.
if (!isUnbreakable) { if (ofLevel == 1) { getCount = GameObject.FindGameObjectsWithTag("Block"); coinCount[0] = getCount.Length; } else if (ofLevel == 2) { getCount = GameObject.FindGameObjectsWithTag("Block"); coinCount[1] = getCount.Length; } . . .
What do I need to do to get the desired effect?