Ok, so this might be a really lame question but it's something I would love to know how to do. I have multiple instances of an object displayed in my hierarchy. When I select all of the objects and try to apply a script to all of them at once, the script is only applied to the first object. Is there anyway to selectively apply one script to multiple objects at once? I really don't feel like dragging and dropping a script onto every object that needs it..., I should be able to apply the script to all of them simultaneously.
Thanks
system
3
Hi, I guess this can help your problem:
Hold Shift or Control to multi-select the Game Objects,
then select the script from the Component > Scripts menu.
It will be added to all the selected objects.
Molix
2
Often if you need to do that sort of thing you'd create a prefab, set it up once, and then duplicate it. That way if you make other changes later, you only have to change it in once place.
However, if for some reason you really need that on different prefabs, you could make a little editor script that did it, e.g.
[MenuItem( "Utils/Add TheComponentYouWantToAdd To Selection" )]
void AddTheComponentYouWantToAddToSelection()
{
foreach( GameObject go in Selection.gameObjects )
{
go.AddComponent<TheComponentYouWantToAdd>();
}
}
You could probably generalize that with some reflective methods, but really, you typically don't need that sort of thing.
26PM
4
Select the objects you want in the hierarchy. In the Inspector tab, click the Add Component button. Click on scripts, then you can search for your script name to add. ( this method is convenient if you have large numbers of scripts )