Search Unity

[SOLVED]GUI.DrawTexture() change opacity

Discussion in 'Immediate Mode GUI (IMGUI)' started by flyber, Sep 16, 2009.

  1. flyber

    flyber

    Joined:
    Sep 14, 2009
    Posts:
    12
    Hi, all

    Can we change opacity for texture witch is drawing as GUI.DrawTexture() ? :roll:
     
  2. HiggyB

    HiggyB

    Unity Product Evangelist

    Joined:
    Dec 8, 2006
    Posts:
    6,183
    Code (csharp):
    1. GUI.color = someColorValue;
    2. GUI.DrawTexture(...);
    3. GUI.color = originalColorValue;
    Just set the opacity you want as the alpha information in someColorValue (for example: new Color(1.0, 1.0, 1.0, 0.25) to have it set to 25%).
     
    Oyedoyin1, whiteflux and nenok1 like this.
  3. flyber

    flyber

    Joined:
    Sep 14, 2009
    Posts:
    12
    Thanks :)
     
  4. Teare

    Teare

    Joined:
    Nov 22, 2010
    Posts:
    30
    Thanks HiggyB, even 3 years later it came in handy :p

    A breakdown for those who want to know, the color class is Color (r,g,b,a). So you could have changed just the alpha (opacity) by setting:

    GUI.color.a = yourAlpha; // value between 0 and 1
     
  5. Quincy

    Quincy

    Joined:
    Jul 5, 2012
    Posts:
    1
    Thanks man, it's really helpful.
     
  6. Smireles

    Smireles

    Joined:
    Jun 20, 2008
    Posts:
    38
    Even 5 years later this is handy. Thanks HiggyB
     
  7. anniyan137

    anniyan137

    Joined:
    May 22, 2012
    Posts:
    2
    Some things are useful no matter how old they are... :)
     
  8. vojtiman

    vojtiman

    Joined:
    Jul 9, 2014
    Posts:
    3
    Well yep... :D thank you after 8 years ;)
     
  9. CyRaid

    CyRaid

    Joined:
    Mar 31, 2015
    Posts:
    134
    GUI.DrawTextureWithTexCoords should really come with a color parameter. It's kinda silly to have to save the state of color yourself for other routines.. At the very least GUI should come with a 'save' state.

    Code (CSharp):
    1. GUI.Begin(State.color);
    2.   GUI.color = Color.red;
    3.   GUI.DrawTextureWithTexCoords(rect, texture, texCoords);
    4. GUI.End();
    Looks a lot better than:

    Code (CSharp):
    1. Color someOldColor = GUI.color;
    2. GUI.color = Color.red;
    3. GUI.DrawTextureWithTexCoords(rect, texture, texCoords);
    4. GUI.color = someOldColor;
    Then again, just like the GUI.DrawTexture, a color could be included and make it even easier:

    Code (CSharp):
    1. GUI.DrawTextureWithTexCoords(rect, texture, texCoords, color);
     
    Oyedoyin1 likes this.
  10. codestage

    codestage

    Joined:
    Jul 27, 2012
    Posts:
    1,931
  11. CyRaid

    CyRaid

    Joined:
    Mar 31, 2015
    Posts:
    134
    Yup, like I stated GUI.DrawTexture() does have a color parameter, but the one with TexCoords does not.. Though, upon reinspection, it looks like the OP doesn't really care about using TexCoords.. So GUI.DrawTexture() would indeed work for those that don't need to use TexCoords and a color parameter. ^_^