Author Topic: How I can set enable or disable NGUI Button  (Read 38174 times)

NJ_kung

  • Guest
How I can set enable or disable NGUI Button
« on: August 06, 2012, 03:03:21 AM »
I try to set GameObject.active = false and that button was disable But it collor and alpha was not change(seem like active button). :-X

Do you have more flexible to not manual change it collor or alpha 8)


PhilipC

  • Guest
Re: How I can set enable or disable NGUI Button
« Reply #1 on: August 06, 2012, 10:48:12 AM »
UIbutton has a isEnabled which should be used to disable buttons (will disable the collider so it cant be clicked). it will also change the color.

NJ_kung

  • Guest
Re: How I can set enable or disable NGUI Button
« Reply #2 on: August 06, 2012, 11:59:16 PM »
I try but the color was not change but The button was disable :)
« Last Edit: August 07, 2012, 12:00:49 AM by NJ_kung »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: How I can set enable or disable NGUI Button
« Reply #3 on: August 07, 2012, 01:32:05 AM »
Make sure the panel the button is on doesn't have the "static" flag turned on (on the UIPanel, not on the game object).

NJ_kung

  • Guest
Re: How I can set enable or disable NGUI Button
« Reply #4 on: August 07, 2012, 01:49:19 AM »
Make sure the panel the button is on doesn't have the "static" flag turned on (on the UIPanel, not on the game object).

It not turn on
« Last Edit: August 07, 2012, 03:13:08 AM by NJ_kung »

PhilipC

  • Guest
Re: How I can set enable or disable NGUI Button
« Reply #5 on: August 07, 2012, 08:02:26 AM »
Have you specified a disabledColor for it? maybe your buttons are grey and the disabled color just looks the same?

judy3t

  • Guest
Re: How I can set enable or disable NGUI Button
« Reply #6 on: August 07, 2012, 11:37:31 PM »
I find that as well as setting the button isEnabled to false, I also have to set the background and label depths to -1.

Judy

NJ_kung

  • Guest
Re: How I can set enable or disable NGUI Button
« Reply #7 on: August 14, 2012, 03:39:35 AM »
Have you specified a disabledColor for it? maybe your buttons are grey and the disabled color just looks the same?

My Btn is white color :)

NJ_kung

  • Guest
Re: How I can set enable or disable NGUI Button
« Reply #8 on: August 14, 2012, 06:35:00 AM »
I find that as well as setting the button isEnabled to false, I also have to set the background and label depths to -1.

Judy

TY  ;)

but now I manual set it color to gray. It look OK :)

schragnasher

  • Guest
Re: How I can set enable or disable NGUI Button
« Reply #9 on: October 10, 2012, 10:30:20 PM »
This helped me get my panels to fade in, but it seems that the button get confused with its disabled colors in the process of fading in and out. i fade out my panel and fade in another, then i fade the second panel out and the first on in, but all the buttons in the first panel get activated in such a way that their colors dont get reset from disabled.

img1 shows the buttons before the fade out, img 2 shows them after fading back in. it seems the UIButton script is getting enabled before the collider so the color stays on the disabled setting.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: How I can set enable or disable NGUI Button
« Reply #10 on: October 11, 2012, 04:27:29 AM »
That's because fade panel script fades in all your sprites, regardless of whether they're foreground or background. Try not using the fade script, or writing a custom script to not include your disabled state widgets.

yozzozo

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Re: How I can set enable or disable NGUI Button
« Reply #11 on: October 31, 2013, 03:52:32 PM »
Just an update, FYI -- I had the same problem and noticed that I was trying to set isDisabled on a UIButton during Start() in my script, and the button probably wasn't initialized yet.  Moving the code to Update() (behind a "do only once" flag) seems to have fixed it.

I noticed the UILabel child wasn't visually updating when disabled, so I added this code to UIButton in UpdateColor():

UILabel label = GetComponentInChildren<UILabel>();
if(label) label.color = c;  //update label tint with disabled color too