Unity: State Based Buttons

Michael Quinn
Unity Coder Corner
Published in
15 min readJun 29, 2023

--

Unity Buttons Suck

When I first started using Unity, I fell in love with the way that you could just make a button. No fuss, no issue, just right-click->UI->Button and you’re done. What more could you need? All a button does is get clicked right?

The late great Charlie Murphy

Let’s take a moment and list out the 6 things a button can possibly do

  1. A button can be clicked
  2. 2. A button can have a color, hover color/effect
  3. A button can be toggled and have more than one state
  4. A button could have text or an icon
  5. A button’s text, icon, color, or shape can change with its state
  6. A button can have a value

The Unity button can handle 4.5 out of 6 of those features. The 1 and a half features that it can’t handle is being able to be toggled and the ability for it to have a baked in value.

So you may be confused about the second part. It is true that a button can be set to a function which has a baked in value so you can get away with this. But take a moment and consider how you would make that system work when you want the value to change between states.

--

--

Michael Quinn
Unity Coder Corner

I’m a foodie and a software engineer. Unity and Unreal developer. See more at MikeQ.dev