Author Topic: [SOLVED] Refreshing the UIButton state based on collider active/inactive?  (Read 3443 times)

ddub

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 18
    • View Profile
I'm working on a tutorial scene for my game. I have a script that turns off all colliders of the children in a panel of mine, then I turn on the ones I want active as users go through the tutorial.

I do want the objects to be a specific color when their colliders are disabled so they know they're not clickable (which thankfully, NGUI does standard).

All is fine except it seems when I deactivate an object with the UIButton component, then eventually turn that object's collider back on, the UIButton doesn't automatically leave the 'disabled' state. It'll change once I hover over the object, but I need it to change back to the 'Normal' state when I enable the object's collider.

Any solution to this? 
« Last Edit: November 29, 2014, 07:29:45 PM by ddub »

ddub

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 18
    • View Profile
Re: Refreshing the UIButton state based on collider active/inactive?
« Reply #1 on: November 29, 2014, 07:29:00 PM »
Ah, sorry. I posted this right before noticing something I hadn't seen before. Solution:

My script now looks like this:

  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class UpdateButtonToggleColliders : MonoBehaviour {
  5.  
  6.         public Collider[] onColliders;
  7.         public Collider[] offColliders;
  8.         public UIButton button;
  9.        
  10.         void OnClick () {
  11.                 foreach (Collider collider in onColliders) {
  12.                         collider.enabled = true;
  13.                 }
  14.                
  15.                 foreach (Collider collider in offColliders) {
  16.                         collider.enabled = false;
  17.                 }
  18.                 button.state = UIButtonColor.State.Normal;
  19.         }
  20. }

Part that solved it is the 'public UIButton button;' and the 'button.state = UIButtonColor.State.Normal;'

Hope others with this issue can see how easy it is to do, sorry for the trouble!