A way for counting breakable blocks

int number_of_block_in_level;
[SerializeField] GameObject block_list;

public void AllBlockInLevel()
{
   number_of_block_in_level= block_list.transform.childCount;
    Debug.Log(number_of_block_in_level);
    if (number_of_block_in_level == 0)
    {
        
        SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
    }
}


public void Update()
{
    AllBlockInLevel();
}

}

In this script i define a blocks parent gameObject that contains all breakable blocks…Using the SerializeField i add the blocks parent gameObject to my script… Then using list.transform.childCount method for counting the children of parent block gameObject…When we press play we see that each time blocks destroyed the number of children decreases…Using LoadNextScene method in if statement we can change to next level…

Privacy & Terms