How can I calculate the "total length" of a series of instantiated gameobjects?

I am trying to calculare at each Update() the total length (as y scale) of a series of instantiated object.
In my case, the script scales a cylinder along the y axis, then at a certain y-scale value, a new cylynder is instantiated as child of the previous one.
How can I calculate the total length as sum of y-scale of each cylinder?
Also, I need to store this total length each update in a variable because I need it to do some other calculations.

For instance, at 3 instantiated cylinders, my situation is like this one in the image:
alt text

each gameobjectMESH has y-scale that I need, while the containers (the gameobjects without “mesh”) have not (y-scale = 1).

So, to summarize, I need to sum each y-scale value of every gameobjectMESH at each Update().

Thank you!

Hello,

You need to browse the tree structure of your Seed object.

For that, you can use Transform.childCount which gives the number of children of the object, and the method Transform.GetChild (int idx), which returns the transform of the child of index idx.

To test whether the length of the object should be taken into account or not, I suggest that you tag the objects to be counted with for example “Cylinder”. You will test the different objects with the GameObject.CompareTag method.

Good luck (and sorry for any mistakes in English).