|
Hi, I need to add a gameobject and all its children to a layer via c# code. In editor i'm asked if i want to add the single object or the whole hierarchy. i wonder if there is an equally fast way to do this in a script without writing explicit code
(comments are locked)
|
|
To put a stop to your wondering, the short answer is that there is no implemented method to do this that I can find. As == says, you will have to recurse through the hierarchy. You could do something like:
or
(comments are locked)
|
|
There is no reason you couldn't recursively move down the top-most object's transform hierarchy and set each gameobject's layer accordingly. Add this script to your Editor folder:
Cheers == I know. I was asking if there is already a method to do this
Sep 02 '10 at 02:40 PM
Patrik
Write the 20-odd lines of code needed to do it?
Sep 02 '10 at 07:17 PM
equalsequals
It's even less. More like 5-13 lines.
Sep 02 '10 at 07:24 PM
skovacs1
Feeling generous, wrote it for you.
Sep 02 '10 at 07:33 PM
equalsequals
Did the question specify whether the code being asked about was for the editor or the run-time? I figured since the editor will do this for you as the question describes that they didn't really need an editor script. Thanks for covering the other interpretation - one of us has to have the correct answer.
Sep 02 '10 at 09:05 PM
skovacs1
(comments are locked)
|
