Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Changing a specific materials color

Discussion in 'Scripting' started by gizzerd91, Aug 23, 2008.

  1. gizzerd91

    gizzerd91

    Joined:
    May 4, 2008
    Posts:
    311
    I have a button object with several materials on it. How do I script just one of the materials to turn green? (to indicate you've already hit the button)
     
  2. gizzerd91

    gizzerd91

    Joined:
    May 4, 2008
    Posts:
    311
    Nobody? Okay I'll simplify my question. How do you change a solid materials color with scripting?
     
  3. podperson

    podperson

    Joined:
    Jun 6, 2006
    Posts:
    1,371
    As my late father would have said, "look it up".

    http://unity3d.com/support/documentation/ScriptReference/Material-color.html

    If you're using the GUI system then materials don't really come into it, so I'm assuming your button is some kind of 3d object.

    Incidentally you can usually access a given object's material fairly easily:

    renderer.material.color

    And get its unique instance (i.e. you can change that color without changing the color of every mesh sharing the material).

    As with most stuff in Unity, it's easier than you have any reasonable right to expect it to be ;-)