Author Topic: isEnabled working but not changing sprite  (Read 1659 times)

Majicpanda

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 83
    • View Profile
isEnabled working but not changing sprite
« on: May 13, 2013, 10:31:20 PM »
I have a Panel that contains a set of widgets, on this GO I have a script and in Start() it gets all the buttons I have in a list and sets them to btn.isEnabled = true or false depending on some criteria.

Problem is the buttons are accurately changing to isEnabled state, but the ones that should be isEnabled = false are not changing to their "Disabled Color" from what it seems.  The collider appears accurately removed and there is no Hover, so the state is changed but not the sprite.

Any help is appreciated.  I tried moving this script to Awake() Start() OnEnabled() with no luck:

  1.         public void EnableDepositButtons() {
  2.                 foreach(UIButton btn in _depositButton) {
  3.                         if(GameManager.Instance.playerData["Player"].lairGold >= (int) btn.gameObject.GetComponent<PlatinumCoinButton>()._betAmount) {
  4.                                 btn.isEnabled = true;
  5.                         }
  6.                         else {
  7.                                 btn.isEnabled = false; 
  8.                         }
  9.                 }              
  10.         }
  11.  

If I hit my UI button that closes and re-opens the Panel that all these buttons are under they accurately show up disabled, it's only the initial opening of the window causing the problem.  The button does a simple window.SetActive(false) or true to the entire Panel and hierarchy.

laurentl

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 188
    • View Profile
    • McDROID
Re: isEnabled working but not changing sprite
« Reply #1 on: May 13, 2013, 11:33:03 PM »
If I understand you, you want to disable some buttons.
I have a script for that, it also grays out the sprites.
Now make sure that your panel is not set as static - happened to me plenty of time.

  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4.  
  5. public class NNToolz : MonoBehaviour {
  6.  
  7.         public static Dictionary<int,Color> colorStore;
  8.        
  9.         public static void RegisterButtons (UIImageButton button)
  10.         {
  11.                 colorStore.Add (button.target.gameObject.GetInstanceID (), button.target.color);
  12.         }
  13.        
  14.         public static void DeactivateButton (UIImageButton button)
  15.         {
  16.                 if (button.GetComponent<NNDontDeactivateThis> ())
  17.                         return;
  18.                
  19.                 if (colorStore == null)
  20.                         colorStore = new Dictionary<int,Color> ();
  21.                 try {
  22.                         colorStore.Add (button.target.gameObject.GetInstanceID (), button.target.color);
  23.                 } catch {
  24.                 }
  25.                 button.target.color = Color.gray;
  26.                 button.collider.enabled = false;
  27.         }
  28.        
  29.         public static void ReactivateButton (UIImageButton button)
  30.         {
  31.                 if (button.GetComponent<NNDontDeactivateThis> ())
  32.                         return;
  33.  
  34.                 button.collider.enabled = true;
  35.                 if (colorStore == null)
  36.                         colorStore = new Dictionary<int,Color> ();
  37.                 try {
  38.                         button.target.color = colorStore [button.target.gameObject.GetInstanceID ()];
  39.                 } catch {
  40.                         colorStore.Add (button.target.gameObject.GetInstanceID (), button.target.color);
  41.                 }
  42.         }
  43. }
  44.