- Home /
Broadcasting message to multiple children
I am having trouble using broadcast message to deselect and deparant multiple objects.
when selected the gameobjects are parented to a gO named "selected" and upon clicking on terrain or single unit, all selected parents are set to 0.
[Sender]...
if(Physics.Raycast(ray, hit))
if(hit.transform.CompareTag("UNIT")){
selected.BroadcastMessage("Deselect",options);
hit.transform.BroadcastMessage("Select",options);
}
if(hit.transform.CompareTag("Terrain")){
selected.BroadcastMessage("Deselect",options);
}
[Reciever]...
function Select () {
selected = true;
transform.parent = selectionParent;
}
function Deselect() {
selected = false;
transform.parent = null;
}
But for some reason only one or two is deselected at a time???
Your logic seems sound... have you tried pausing the game while multiple units are selected and ensuring that they really all do share the same global selectionParent
? What you've posted looks ok to me, but maybe somewhere else in your code the parent is being changed.
yeh, checked that half the reason they are parented is so i can see it in the Hierarchy. Been racking my brains over it for a week now. Is it possible to stick them in an array or something ins$$anonymous$$d ?
Answer by DaveA · Jul 23, 2011 at 04:17 PM
If you are reparenting them just to keep like a list of them, use an array or list instead. Only reparent if you really need to have them move or behave as a group. For example, if you had two flocks of birds and you wanted to move some birds from one flock to another. If you're just keeping track of 'selected or not' why not just examine your 'selected' vars? Also consider using layers or tags.
Your answer
Follow this Question
Related Questions
Make a simple tree 1 Answer
How to detect child object collisions on parent 3 Answers
Instantiating as a child error 1 Answer
How do I allocate a parent to a gameobject that just got instantiated? 2 Answers
Rotate children around parent pivot 0 Answers