I would like to select multiple objects in the scene and change a common property on all of them.
For example, select many pieces of terrain and change the material they use by selecting a new one in the mesh renderer component from the editor. Currently this will only change the property of the first object I selected. Is there a correct way to do this or is it not supported?
If it’s not supported is there a good example of code that will run through each child object of a game object and change a property, something I can run during the initialization of the level? My searching the forum and wiki hasn’t come up with anything.
Here’s an Editor script that does this…
class AssignMaterial extends ScriptableWizard
{
var theMaterial : Material;
function OnWizardUpdate()
{
helpString = "Select Game Obects";
isValid = (theMaterial != null);
}
function OnWizardCreate()
{
var gos = Selection.gameObjects;
for (var go in gos)
{
go.renderer.material = theMaterial;
}
}
@MenuItem("Custom/Assign Material", false, 4)
static function assignMaterial()
{
ScriptableWizard.DisplayWizard(
"Assign Material", AssignMaterial, "Assign");
}
}
And here’s a link to a similar thread about this topic:
http://forum.unity3d.com/viewtopic.php?p=234762
BRILLIANT! Thanks aNTeNNa trEE!