A couple of questions from a newbie

Ok, since i am pretty new to unity (just 30 days and counting) and i am trying to start a decent project I’d have a couple of questions for you, and sorry if they sounds too noobish.

  1. I have a GameObject, let’s call that House1 and I want to send all childrens a message, or tell them to execute a function
  2. In this GameObject, i want to execute a code for every child in this object parent ( I know how to use loops, etc, it’s just the way to know how many childs has the script parent that i don’t know)

Pseudocode:

var thisObject :GameObject

function Start()
{
     thisObject = ThisScript.parent
}

function Update()
{
     thisObject.SendMessage("newHouseCreated")
  
    for (i = 0; thisObject.childCount > i; i++) 
    {     //See N°2 in the post, if  you skipped it
        executethatcode       
    }
}

Thanks for any help
EDIT = corrected the pseudocode

Philip

newHouseCreated() would be in the script on the children

Yeah, i Saw that, but maybe i misinterpreted GameObject.Broadcastmessage…

Isn’t GameObject a gameObject variable you have to provide? much like

thisGameObject.BroadcastMessage
or
newHose.BroadcastMessage

or if i write down
“GameObject.BroadcastMessage”
it is broadcasted to this gameobject and all it’s children?

Well, if any script on that object says gameObject.BroadcastMessage(“FunctionName”, passedVariable), then every single script in the GameObject and its children with a function named FunctionName will run that function. The passedVariable is just where you put the first input for the function you’re calling.