It works. My question is: should I just think “if it works, it’s good”, or is there an underlying threat to my solution (for example, in a future scenario)?
Solution:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class Level : MonoBehaviour
{
int numberBlocks;
private void Awake()
{
GameObject blocks = new GameObject("Blocks");
}
// Start is called before the first frame update
void Start()
{
countBlocks();
//Debug.Log(blocks.name + " has " + blocks.transform.childCount + " children");
}
private void countBlocks()
{
GameObject blocks = GameObject.Find("Blocks");
numberBlocks = blocks.transform.childCount;
}
// Update is called once per frame
void Update()
{
countBlocks();
Debug.Log(numberBlocks + " blocks left");
if (numberBlocks == 0)
{
SceneManager.LoadScene("Win");
}
}
}