- Home /
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?
Answer by tormentoarmagedoom · Feb 27, 2020 at 03:39 PM
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 https://docs.unity3d.com/Manual/Tags.html
2-At the start of the scene, create a array with all objects with that TAG https://docs.unity3d.com/ScriptReference/GameObject.FindGameObjectsWithTag.html
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!
Your answer
Follow this Question
Related Questions
creating and using list of prefabs 2 Answers
Running scripts from editor 1 Answer
Point Counter Works Only Once! 1 Answer
Having trouble coding an on/off toggle for an animation in script. Please help! 1 Answer
How do I make do I make a variable go back to its original value for a spell system 1 Answer