Author Topic: Disabling button inside tab content  (Read 4042 times)

fanling3

  • Newbie
  • *
  • Thank You
  • -Given: 4
  • -Receive: 0
  • Posts: 29
    • View Profile
Disabling button inside tab content
« on: March 20, 2014, 10:21:29 PM »
Hi all, I have a Tab panel using UIToggle (basically the same as NGUI Example 13), and I have several UIButtons inside each tab. I want to disable the button after I click on it, so I have written a function using isEnabled = false and put it in onClick event of the buttons.

It looks cool when I click on the buttons, they turn grey, but when I switch to another tab and switch back. The buttons become blue color again, though I cannot hover them or click them. But they are in blue color. How to fix this? Thanks.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Disabling button inside tab content
« Reply #1 on: March 21, 2014, 01:54:02 PM »
Here's what I just tried.

1. Opened the Tabs example.
2. Dragged in the "Control - Simple Button" under "Content 1" object.
3. Added this script to it:
  1. using UnityEngine;
  2.  
  3. public class Test : MonoBehaviour
  4. {
  5.         void OnClick ()
  6.         {
  7.                 GetComponent<UIButton>().isEnabled = false;
  8.         }
  9. }
4. Hit Play, clicked the button -- it became gray.
5. Switched to the second tab, then back to the first. The button is still gray.

fanling3

  • Newbie
  • *
  • Thank You
  • -Given: 4
  • -Receive: 0
  • Posts: 29
    • View Profile
Re: Disabling button inside tab content
« Reply #2 on: March 23, 2014, 09:17:56 PM »
I tried the above but when I switched back to tab1 the simple button becomes bright again. I tried to print GetComponent<UIButton>().isEnabled and confirmed that it is false after I clicked it and switch back to tab1 from tab2, and the button cannot be clicked, however the button is still bright in color.

Cause the thing NGUI did for activating the tab content is just SetActive(true) to all game objects under the tab, I think the above script has nothing to do with the initial color of the button. When I click on tab2, the color of the simple button will change to normal state.

I am using NGUI 3.5.3
« Last Edit: March 23, 2014, 09:24:34 PM by fanling3 »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Disabling button inside tab content
« Reply #3 on: March 24, 2014, 03:50:55 PM »
I did the test with NGUI 3.5.5.

fanling3

  • Newbie
  • *
  • Thank You
  • -Given: 4
  • -Receive: 0
  • Posts: 29
    • View Profile
Re: Disabling button inside tab content
« Reply #4 on: March 24, 2014, 08:42:50 PM »
I updated NGUI and it works without the above script. Seems the latest version fixed it already. Thanks.