I ended up finding a solution to this problem that was not quite what Rick was suggesting with his hint. So far in all my levels I have been keeping all my blocks in a parent game object I call block storage. I thought wouldn’t it be easier to just count how many children are in block storage. Given that I already planned to standardize my block storage on each level it made sense to me to do it this way and reduce the total amount of code needed.
I’m happy to report that it works. I was able to move to the next scene once all the blocks were gone.
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class LevelController : MonoBehaviour
{
[SerializeField] private int numberOfBlocks;
[SerializeField] private GameObject blockStorage;
[SerializeField] private string nextScene;
// Update is called once per frame
void Update()
{
AddUpBlocks();
if (numberOfBlocks == 0)
{
SceneManager.LoadScene(nextScene);
}
}
private void AddUpBlocks()
{
numberOfBlocks = blockStorage.transform.childCount;
}
}