Search Unity

Unity UI How do button transitions work?

Discussion in 'UGUI & TextMesh Pro' started by Antistone, Apr 19, 2018.

  1. Antistone

    Antistone

    Joined:
    Feb 22, 2014
    Posts:
    2,836
    Buttons can specify various color tinting for an Image based on the button state (normal/highlight/press/disabled).

    If you look at the inspector while the game is running, the Image's "base" color does not change as the Button animates. If you use a very long transition time, you can even use the inspector to change the Image's color in the middle of a transition, and the Button will continue smoothly transitioning between its tints on the new base color.

    How does it do that? Can I write my own custom MonoBehaviour that can modify an Image's apparent color without actually changing its "color" property?
     
  2. Hosnkobf

    Hosnkobf

    Joined:
    Aug 23, 2016
    Posts:
    1,096
    yes, you can do this.
    Every Graphics component (Image, RawImage, Text, ...) has two methods which you can use to do a transition:
    - CrossFadeColor
    - CrossFadeAlpha

    They will not touch the color in the component but will change the color of the vertices anyways.