how do i tell how many childs a object has

Im making a script that loops threw childs of a object and i need the script to know how many childs it has so that it know when to go back to 0.

here’s a demonstration

var holder : GameObject;
var number : int = 1;

function Update()
{
  if(somthing Happens)
  {
   number += 1;
//some how make this "if" know when "holder" runs out of childs
if()
   {
     number = 0;
   }
  }
} 

thanks in advance :] and thumb up this question plz

  1. Declare an array containing the children : Transform[] children.
  2. Populate the array as follow: children = gameObject.GetComponentsInChildren<Transform>();
  3. You can now check the length of the array using children.Length to get the total number of children

Also Transform.childCount works too

1 Like

I think this will point you in the right direction Here