Search Unity

name that shader!

Discussion in 'Scripting' started by DannyJ, Apr 29, 2008.

  1. DannyJ

    DannyJ

    Joined:
    Sep 3, 2007
    Posts:
    40
    This is a scripting question...

    How do I read the name of the shader used by the material of a renderer? I want the name as it appears in the drop down menun in the inspector so that I can change it to and from a transparent version of the same kind.

    Thanks!

    -Dan
     
  2. thomasvdb

    thomasvdb

    Joined:
    Feb 28, 2008
    Posts:
    85
    I did a little test and this gave me the name of the shader:

    Code (csharp):
    1.  
    2. renderer.material.shader.name
    3.  
     
  3. DannyJ

    DannyJ

    Joined:
    Sep 3, 2007
    Posts:
    40
    There is still an issue because

    Code (csharp):
    1. renderer.material.shader.name
    returns strings such as "Normal-Glossy" instead of Specular as it appears in the menu and "Alpha-Glossy" instead of Transparent/Specular.

    Since I am hoping to use Shader.Find ("name") to get the transparent version for the shader currently in use, I think that "name" needs to be identical to the name in the menu or else it won't work.
     
  4. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    Whoops, right, a glaring omission indeed. Will be fixed in upcoming Unity 2.1: shader.name will return the actual name of the shader, and not the filename.