Search Unity

  1. We're looking for feedback on Unity Starter Kits! Let us know what you’d like.
    Dismiss Notice
  2. Unity 2017.2 beta is now available for download.
    Dismiss Notice
  3. Unity 2017.1 is now released.
    Dismiss Notice
  4. Introducing the Unity Essentials Packs! Find out more.
    Dismiss Notice
  5. Check out all the fixes for 5.6 on the patch releases page.
    Dismiss Notice
  6. Help us improve the editor usability and artist workflows. Join our discussion to provide your feedback.
    Dismiss Notice

Label Background Color

Discussion in 'Extensions & OnGUI' started by wbl1, Oct 9, 2009.

  1. wbl1

    wbl1

    Joined:
    Apr 22, 2009
    Posts:
    151
    I basically just want to create a "color map" - a series of boxes - each filled with a different color. This would be analogous to background-color in CSS.

    How do I do this? It seems that the normal states in skins / styles require a texture (image) - not just a simple color input.
     
  2. HiggyB

    HiggyB

    Unity Product Evangelist

    Joined:
    Dec 8, 2006
    Posts:
    6,185
    Yup, so create a set of small (2x2 even) background boxes of the various colors you'd like, then create unique GUI Styles for each color set-up you'd like and away you go! :)
     
  3. wbl1

    wbl1

    Joined:
    Apr 22, 2009
    Posts:
    151
    As I make my way through the docs I see that I need to define a GUIStyleState. This has two variables -- background and textColor. Trouble is, background is an image (Texture2d). This is where I get into trouble. I would expect to see a variable called backgroundColor.

    Do I need to define a new "texture" for the color? If so, is there an example of how to do this?

    The "texture" concept is where I get into trouble -- this is a new paradigm for me I am afraid ...

    Thanks!!
     
  4. NicholasFrancis

    NicholasFrancis

    Joined:
    Apr 8, 2005
    Posts:
    1,587
    The simplest way would be to use a white texture, then assign the color you want to GUI.backgroundColor. The change sticks around so you should make sure to revert the value when you're done.
     
  5. wbl1

    wbl1

    Joined:
    Apr 22, 2009
    Posts:
    151
    OK, I know my ignorance is irritating, but this is what I dont understand:

    Where do I get a simple white texture? Is this something I can create in Unity? Is it an image? Where does this come from?

    Thanks!

    :oops:
     
  6. sebako

    sebako

    Joined:
    Jun 27, 2009
    Posts:
    298
    you can create it with any image manipulation program you like. Maybe Gimp or Photoshop
     
  7. wbl1

    wbl1

    Joined:
    Apr 22, 2009
    Posts:
    151
    OK, Thanks very much all ...

    For my friends at Unity, it seems that a straightforward backgroundColor - that does not require an image to start with - would be a sensible item for the wish list.
     
    Sabo likes this.
  8. sebako

    sebako

    Joined:
    Jun 27, 2009
    Posts:
    298
    yes it would be nice to switch background colors like in Css ;)
     
  9. KokodokoGames

    KokodokoGames

    Joined:
    May 20, 2014
    Posts:
    2
    Unity GUI is an awful nightmare if you come from CSS. Why not let us display a HTML field with CSS?
     
  10. Gabb01

    Gabb01

    Joined:
    Mar 22, 2016
    Posts:
    1
    Because CSS is an awful nightmare if you come from Unity GUI.