Author Topic: UIButton.isEnabled strage behaviour  (Read 3137 times)

Markov

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 27
    • View Profile
UIButton.isEnabled strage behaviour
« on: October 15, 2013, 05:33:59 AM »
How do disable and enable UIButtons now? I need btn color to be disabled color, but now it's still normal.
I'm used to disabling them like this(in 2.7x):
nextButton.GetComponent<UIButton>().isEnabled = false;

And what I see now:


Button switched off, but button's color still normal(not grey)

macy

  • TNP Alpha
  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 2
  • Posts: 8
    • View Profile
Re: UIButton.isEnabled strage behaviour
« Reply #1 on: October 15, 2013, 06:44:14 PM »
Try:

UIButton button = nextButton.GetComponent<UIButton>();
button.isEnabled = false;
button.UpdateColor(false, true);

Markov

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 27
    • View Profile
Re: UIButton.isEnabled strage behaviour
« Reply #2 on: October 15, 2013, 07:27:41 PM »
Same effect  :-[

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIButton.isEnabled strage behaviour
« Reply #3 on: October 16, 2013, 02:23:10 AM »
Disable its collider instead. There's a typo in isEnabled. It should be:
  1.         public bool isEnabled
  2.         {
  3.                 get
  4.                 {
  5.                         if (!enabled) return false;
  6.                         Collider col = collider;
  7.                         return col && col.enabled;
  8.                 }
  9.                 set
  10.                 {
  11.                         Collider col = collider;
  12.                         if (col != null) col.enabled = value;
  13.                         else enabled = value;
  14.                 }
  15.         }

Markov

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 27
    • View Profile
Re: UIButton.isEnabled strage behaviour
« Reply #4 on: October 16, 2013, 10:20:07 AM »
Thanks. It works.
But if I want to enable and disable buttons dynamicly it works only with UpdateColor(val, true)
It will be very handy if you return back enable/disable behaviour as it was in 2.7x versions.
« Last Edit: October 16, 2013, 10:25:15 AM by Markov »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIButton.isEnabled strage behaviour
« Reply #5 on: October 16, 2013, 01:02:58 PM »
I just had a second look at this, and I retract my previous statement. There is no typo, and how it is is intentional. Furthermore, it works perfectly fine with the following test script:
  1. using UnityEngine;
  2.  
  3. public class Test : MonoBehaviour
  4. {
  5.         void Update ()
  6.         {
  7.                 if (Input.GetKeyDown(KeyCode.G))
  8.                 {
  9.                         GetComponent<UIButton>().isEnabled = !GetComponent<UIButton>().isEnabled;
  10.                 }
  11.         }
  12. }