- Home /
Material replacement on multiple objects in editor
I import a scene from a 3d app and I want to replace some of the materials imported with the scene with materials already developed in Unity after import of a previous scene. Is there a simple way to do it in one go on multiple meshes? How is the simplest to setup a script to select all the objects with a specified material and swap this material to another one?
It seems there is no way of selection by materials like in 3dsmax. I will try to do it by writing a simple script.
Answer by tomekkie2 · Jun 21, 2011 at 05:57 AM
I wrote a simple script myself.
var sourceMaterials : Material[];
var targetMaterials : Material[];
function Start () {
var n = sourceMaterials.length;
for (var i=0; ivar shader1: Shader = targetMaterials[i].shader; sourceMaterials[i].shader = shader1; sourceMaterials[i].CopyPropertiesFromMaterial (targetMaterials[i]); } }
I am trying to do the same thing, but replace a mesh, having a hard time getting the editor script to work correctly. I have RR tracks, and I want to replace the ties with a lower polygon version, but don't want to do it by hand. Thought this would be fun as well...
The above script is a runtime, not editor script. But it does its work, anyway.