Counting prefabs in screen?,Problem with counting prefabs in screen

Hi! I’m building a very simple game in which a character is moving and removing ground around it (think of dig dug). When the character has removed all the ground the game should just restart. But how can i registrate the prefabs and send the signal to the scene management?

Hello.

First advice:, when coming here, you need to ask the correct question, in the correct way to get the correct answer…

As i understand you are really asking this: How can a script be aware that all specyfic objects in the scene has been destroyed?

So, Its hard to guide you, if you dont show us how are you doing this :" removing ground around it" each ground have its own script? they are childs of a bigger obect? Are you destroying them, or just seting Unactive?, Are you using colliders, or triggers? are you using Vector3Distance…

As you see, Its almost impossible guide you if we dont know which way you are doing your stuff… So second advice : ALWAYS GIVE YOUR RELEVANT CODE! (only the relevant, if come and post 150 lines of code, nobody will read it)

But, i recommend you to learn about this procedure:


1- TAG all ground objects the same way Unity - Manual: Tags

2-At the start of the scene, create a array with all objects with that TAG Unity - Scripting API: GameObject.FindGameObjectsWithTag

3- Everytime a ground is destroyed, check how many objects of that array are still “alive” (So they are not null"

4- Once all elements in the array are null, it means no more ground in the scene.


Bye!