Enlarge a button when it is in focus?

Hi, I was wondering if there was a simple way to execute a function ONCE when a button has been focused on?

I threw this on to the Update function just to see if it would work, and it did:
es = event system reference
btnA = the button being focused on

if (es.currentSelectedGameObject == btnA.gameObject) {
      btnA.transform.localScale += new Vector3(0.1F, 0.1F, 0);
}

But I am unsure how to make it execute only ONCE when a button has been focused on, without adding an enlarged boolean for every single button I have - there are a few. I was hoping there was just a function like “onFocus” or something, but I can’t seem to find it. Any ideas?

Google, first link. For a nail use a hammer, not a universal tool…

Basically make button an animated button. Make animation just scale button when mouse is over it.

Well, yes, if you know what to Google I am sure it’s very likely that it will come up as the first link.

Thank you for the video. However I am wanting to enlarge the button through script, not the animation system.

http://docs.unity3d.com/ScriptReference/EventSystems.IPointerEnterHandler.html
http://docs.unity3d.com/ScriptReference/EventSystems.IPointerExitHandler.html

implement those two interfaces, they’re basically the “OnMouseEnter” and “OnMouseExit” of EventSystem interfaces

1 Like