I want to replace all the shaders on all the objects in my game which have specular shaders already attached. I have the following script but this only seems to replce the first material in each object. How do I get it to replace ALL the materials of type Legacy Shaders/Lightmapped/Specular in an object??
note this code only uses selected objects too...ideally I want to auto select everyobject in the scene.
@MenuItem("MIHT/Mass Material Replace")
static function MassMaterialReplace() {
Undo.RegisterSceneUndo("MassMaterialReplace");
var materialOld = Shader.Find ("Legacy Shaders/Lightmapped/Specular");
var materialNew =Shader.Find ("Legacy Shaders/Lightmapped/Diffuse");
for (var obj : GameObject in Selection.gameObjects)
{
if(obj.renderer.sharedMaterial.shader==materialOld)
{
obj.renderer.sharedMaterial.shader=materialNew;
}
}
}
P..S..this code is modified from a function on the wiki.