Search Unity

Fade rich text with <color> tags.

Discussion in 'Immediate Mode GUI (IMGUI)' started by OneManArmy3D, May 17, 2014.

  1. OneManArmy3D

    OneManArmy3D

    Joined:
    Jun 2, 2011
    Posts:
    191
    Hi,
    any ideas how to fade rich text when we use "<color=green> text </color>" tags?
    Maybe somehow by using hexadecimal digits "<color=#008000ff> text </color>"?

    In this case "GUI.color.a" doesn't work and i understand why, but i can't figure out how to fade with color tags :/
     
    rakkarage likes this.
  2. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,692
    I suppose you could try to fade by going from <color=#008000ff> to <color=#00800000> (I haven't tested this), but setting the GUI style's alpha value should work. Use a custom GUIStyle (e.g., GUIStyle myGuiStyle = new GUIStyle(GUI.skin.label)) and change myGuiStyle.normal.textColor.a. You want to change the alpha of the text color, not the background color.
     
  3. Tagi

    Tagi

    Joined:
    Feb 21, 2014
    Posts:
    3

    Like this? (see webplayer) ;)

    That's a nudge-wink that if you buy the asset you can see how it is done. Sorry, i couldn't be any more helpful :confused:, but it wasn't a simple task.
     
    Last edited: Jun 5, 2014
  4. Lukasz_LDCreations

    Lukasz_LDCreations

    Joined:
    Jul 14, 2014
    Posts:
    1
    You can use material on the Text object to do it.
    Create material, set shader to GUI/Text shader
    Then you can modify it like that: GetComponent<Text>().material.color = new Color(1,1,1,a);
     
    MattWhiting likes this.
  5. joihelgi

    joihelgi

    Joined:
    Jan 21, 2014
    Posts:
    19
    You can use CanvasRenderer.SetAlpha, best way to fade UI..
     
  6. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,692
    The OP was asking about legacy Unity GUI. (This is the legacy GUI forum. ;))

    For Unity UI, I agree that changing alpha (e.g., CanvasGroup.alpha or Text.color.alpha) is the way to go. You can even control it in an animation clip so you don't need to write any code.
     
  7. joihelgi

    joihelgi

    Joined:
    Jan 21, 2014
    Posts:
    19
    Ooo sorry, found this on google, I had troubles with rich text color and using text.color to fade (had no effect on color tagged part of text), but CanvasRenderer.SetAlpha works nice
     
    feimennaodianlu likes this.
  8. feimennaodianlu

    feimennaodianlu

    Joined:
    Apr 1, 2016
    Posts:
    1
    Thanks a lot! Your reply is helpful to me. From China Shanghai.
     
    joihelgi likes this.
  9. dradb

    dradb

    Joined:
    Jan 10, 2015
    Posts:
    86
    I think it must be a bug. Mechanim is fine to fade text with alpha, but not when it has color tags.