Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice

Change the shader of multiple materials

Discussion in 'Scripting' started by nickavv, Mar 1, 2008.

  1. nickavv

    nickavv

    Joined:
    Aug 2, 2006
    Posts:
    1,801
    How can I do something like so:

    renderer.materials.shader = Shader.Find("Diffuse")

    I need to change the shader of all materials of multimaterialed objects, and am having minimal luck.
     
  2. User340

    User340

    Joined:
    Feb 28, 2007
    Posts:
    3,001
    Try this:

    Code (csharp):
    1. for (m in renderer.materials)
    2.      m.shader = Shader.Find ("Diffuse");
     
  3. nickavv

    nickavv

    Joined:
    Aug 2, 2006
    Posts:
    1,801
    I knew I wanted to do some kind of loop, but it wasn't quite like that. Thanks again Daniel. :D