Search Unity

I want to change the material in c# script.

Discussion in 'Editor & General Support' started by ArcDragon, Mar 20, 2012.

  1. ArcDragon

    ArcDragon

    Joined:
    Feb 21, 2012
    Posts:
    23
    Hello! I am currently using the object with the bumped diffuse.
    It is equipped with BaseTexture and NormalmapTexture.
    So I want to change the material.What should I do?
     
  2. kiranmaya

    kiranmaya

    Joined:
    May 27, 2010
    Posts:
    215
    Code (csharp):
    1.  
    2.  
    3. public Material newMat1 ;
    4. public Material newMat2 ;
    5.  
    6.  
    7. void Update()
    8. {
    9.         if( Random.value < 0.5f)
    10. {
    11. renderer.material = newMat2;
    12. }else renderer.material = newMat1;
    13.  
    14. }
    15.  
    16.  
    17.  
    18.  
    19.  
    i hope this helps
     
  3. ArcDragon

    ArcDragon

    Joined:
    Feb 21, 2012
    Posts:
    23
    Thank you! kiranmaya!
    You've been a great help!
     
unityunity