Search Unity

Handling Button transition events in code

Discussion in '2D' started by mrzappit, Aug 9, 2019.

  1. mrzappit

    mrzappit

    Joined:
    Jan 10, 2019
    Posts:
    5
    From what I can gather, there is no way to handle the Pressed, Normal, Disabled, and Highlighted transitions from code. In other words, I don't see any way to register for any event that alerts my script when these transitions are taking place or have just taken place.

    I have provided a way to customize the colors used for buttons so the user can adjust the UI to suit their preferences. Each button has a border, background, and icon, each of which can be colored separately. Using the Tint transition mode for my button only applies the tint to the image associated directly with the script (the border). I know I can update the colors for each image using an animation, but I have no way of updating the animation from script.

    I have concluded that detecting when the button is in each transition state and adjusting the colors from script is the only way for me to do this. I know I can mostly handle this with a state table using the mouse down and up events, but that only works if the user is not manipulating the buttons with the keyboard.

    Am I missing something? The last forum posts that I saw concerning this were several years ago, so I am really just hoping that things have changed and I'm just not seeing it. Any suggestions would be very much appreciated.