Author Topic: How to Create a Toggle Image Button  (Read 5750 times)

Isamson

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 52
    • View Profile
How to Create a Toggle Image Button
« on: May 17, 2013, 08:21:20 AM »
Hi Guys, here's my second noob question!

Objective: Create an image button that has 2 states: not pressed and pressed. I want to click the button and have the pressed image stay there (this would open a menu for example). The I want to be able to click it again and have it display the not pressed image (and have the menu close).

What I did: I've read this post: http://www.tasharen.com/forum/index.php?topic=2977.msg14993#msg14993 but I noticed that I can't assign a "Check Sprite" from my imageButton since they are selected from a drop down box. So I created a new Sprite that I've put inside the imageButton. I've disabled the sprite and added a both UICheckbox and UICheckbox Controlled Object scripts. Seemed to work fine except that once the sprite appears, it hides the button and I can't see the "hover" state when the button is in the pressed state!

The other Idea I had was to create 2 different buttons and have them activate and deactivate when pressed, but that sounds sloppy...

Any idea how to do what I want without having to create a new script? Is there a function that allows me to inverse the normal and pressed sprite upon click?
Unity 4.5.3f
NGUI 3.7.0

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: How to Create a Toggle Image Button
« Reply #1 on: May 18, 2013, 03:20:53 AM »
Don't use an image button. Use a sprite with a collider on it. Write your own custom script that changes the sprite's spriteName in OnClick.