- Home /
Grouping GameObjects by script
hi folks!
i was wondering if its possible to define something like a group and collect some objects in it to manipulate them as one.
f.e. when you instantiate some GameObjects and then you want them to center around one point.
thanx!
Answer by spinaljack · Apr 22, 2010 at 02:32 PM
You can group objects by giving them the same tag or if you want them to move together you can make them the children of the same game object with transform.parent
something like:
function makechild(){
objs = GameObject.FindGameObjectsWithTag ("things to group");
for (obj in objs){
obj.transform.parent = parentObj.transform;
}
}
You need to define what you want to parent the game objects to
thanks! but easy, vote hunter. :-) and how do you create a new Empty at runtime?
You can create an empty game object in a prefab and instantiate it like so: parentObj = Instantiate(parentPrefab, transform.position, transform.rotation);
Your answer
Follow this Question
Related Questions
How to make a character bounce? 0 Answers
How can i group together ParticleSystems in JS 1 Answer
difference between GameObject.Find() and FindGameObjectWithTag 1 Answer
How to use a script on multiple gameobjects, then change a variable for one of them, not the other. 3 Answers
How To Hide Game Objects That Aren't In Pause Script 1 Answer