How to simpy (Get multiple child value)

Hi everybody ! I’m a begginer with unity and c# and sorry for my bad english ^^

i would like to know how it’s can be possible to simplify my code. i want to get the valu of multiple child and add themself

i do something like this :

        DEF = (SlotPanel.GetChild(0).GetComponent<StatsSlots>().DEF) + (SlotPanel.GetChild(1).GetComponent<StatsSlots>().DEF) + (SlotPanel.GetChild(2).GetComponent<StatsSlots>().DEF)+
            (SlotPanel.GetChild(3).GetComponent<StatsSlots>().DEF)+ (SlotPanel.GetChild(4).GetComponent<StatsSlots>().DEF) + (SlotPanel.GetChild(5).GetComponent<StatsSlots>().DEF) +
            (SlotPanel.GetChild(6).GetComponent<StatsSlots>().DEF) + (SlotPanel.GetChild(7).GetComponent<StatsSlots>().DEF);

but i think that is a complicate and longer way ^^
So if someone can give me a trick ?

Thx for reading me, have a good night :slight_smile:

Oh thx! But i don’t really understand this part:

        foreach (HingeJoint joint in hingeJoints)
            joint.useSpring = false;

how can i get my valu here ? :confused:
if i follow the exemple with my valu that i want to add with other same valu :

        foreach (HingeJoint joint in hingeJoints)
            joint.DEF = DEF;

that is correct? ^^

Thx for you’re help!

untested uncompiled code:

StatsSlots[] statSlots = SlotPanel.GetComponentsInChildren<StatsSlots>();
for( int i = 0; i < statSlots.Length; ++i )
{
  DEF = DEF + statSlots[i].DEF;
}

Something like that should do the trick.

Ooh! I see! Thx ! I will try like that !

Thanks for you’re help! have a good day ! :slight_smile: