0

How can I set the state of a button via a script?

Example:

button.Hover == true;
GrandMasterFlush
  • 6,269
  • 19
  • 81
  • 104

2 Answers2

2

You can add the OnHover method to your scripts placed on widgets or in-game objects with a collider, provided they are drawn with a camera that has the UICamera script attached. Like this:

void OnHover (bool isOver) {
    someState = isOver
}

More info about this here.

But if you just want to use this control to change settings of the button, you don't need to do this, all you gotta do is use NGUI's button scripts (like UIButton) and set its configuration. For example, you can set it's background texture to change to another color if it's on hover.

Roberto
  • 11,557
  • 16
  • 54
  • 68
0
button.SetState(UIButtonColor.State.Hover, bool);

The bool controls whether or not to skip the color animation. True skips.

Edit: button.state = UIButtonColor.State.Hover; automatically calls SetState with bool = false.

Inlight
  • 11
  • 1