c# - How can I create a code that will automatically apply shaders to the materials of the objects in the model? -


i have code in c# reads materials of tagged object , renders based on shader want use. know if there more easier way this. in model there lot of objects have lot of materials. time consuming create these many scripts , run them on uniy3d. want create script automatically find materials of objects in model , apply shaders them.

put on parent gameobject , should work, finds of renderer's in children of game object , assigns shader.

using unityengine; using system.collections;  public class assignshaderstochildren : monobehaviour  {     public shader shader; // should hold shader want use      void start()      {         // create list hold renderers can assign shader         list<renderer> renderers = new list<renderer>();         renderers = getcomponentsinchildren<renderer>();          // every renderer in list assign materials shader shader         foreach (renderer r in renderers) {             r.material.shader = shader;         }     } } 

note: written without compiler there chance not run.

if answers question sure accept answer.


Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -