- Home /
Children Overproducing
In a predicament.
Ol gameObject 1 and gameObject 2 have been getting together on the weekends and giving me spawns. They dont stop!
Now i have too many.
What can i do. The buggers are everywhere. In a way i guess i want to abort all future children from being instantiated under an object once i reach a nice number like 24. What script functions should i use to achieve this?
Thanks for the help.
Ins$$anonymous$$d of using a fairly vague metaphor, could you show us the actual code? It'll be much easier to understand the root cause. What is the intended behaviour?
0 Well thats the reason i gave a vague metaphor. To be a smartass and there is no Code yet. I am wondering if anyone has specific Unity recommended code references to use to achieve this type of effect or perhaps has had experience with this type of setup before.
I would be trying to limit the children via a hard cap under my parent so that i could limit the amount of instantiated player prefabs
I also was more vague then i meant to be. $$anonymous$$y bad on that. I am simply trying to set a limit to gameObjects Instantiated under a parent.
Thanks for the responses. I will get cracking and post what i used when i get it working.
Answer by whydoidoit · Jun 16, 2012 at 09:45 AM
Not sure what language you want the code in, but you basically need to count the number of items that are contained in the parent's transform.
import System.Linq
...
parentObject.transform.Cast.<Transform>().Count();
Would do it in UnityScript
But you'd probably be better of just having a count variable on the parent and increment it each time you Instantiate a child
Your answer
Follow this Question
Related Questions
Make a simple tree 1 Answer
Make object A parent of object b 1 Answer
Get Child from a parent 3 Answers
spawning object as child of other:error 2 Answers
Problem with child and parent. 1 Answer