x


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.

more ▼

asked Jun 16 '12 at 07:35 AM

alternativee30 gravatar image

alternativee30
0 2

Instead 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?

Jun 16 '12 at 07:41 AM syclamoth

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

Jun 16 '12 at 11:14 AM alternativee30

I also was more vague then i meant to be. My bad on that. I am simply trying to set a limit to gameObjects Instantiated under a parent.

Jun 16 '12 at 11:15 AM alternativee30

Thanks for the responses. I will get cracking and post what i used when i get it working.

Jun 16 '12 at 11:17 AM alternativee30
(comments are locked)
10|3000 characters needed characters left

1 answer: sort newest

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

more ▼

answered Jun 16 '12 at 09:45 AM

whydoidoit gravatar image

whydoidoit
33k 11 23 100

But you'd probably be better of just having a count variable on the parent and increment it each time you Instantiate a child

Jun 16 '12 at 09:46 AM whydoidoit
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3731
x440
x422
x410

asked: Jun 16 '12 at 07:35 AM

Seen: 275 times

Last Updated: Jun 16 '12 at 11:17 AM