Author Topic: OnEnable/OnDisable  (Read 4181 times)

AndyGFX

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 24
    • View Profile
    • AndyGFX
OnEnable/OnDisable
« on: September 16, 2012, 01:22:07 PM »
I have assigned script to a few game objects with UI childs this script for visibility controll when GUI items are showed:

  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class VisibleByCheckbox : MonoBehaviour
  5. {
  6.        
  7.         public UICheckbox cb;
  8.        
  9.         void OnEnable()
  10.         {              
  11.                 NGUITools.SetActive(this.gameObject,cb.isChecked);                                             
  12.         }
  13.        
  14.        
  15.         void OnDisable()
  16.         {
  17.                 NGUITools.SetActive(this.gameObject,cb.isChecked);                             
  18.         }
  19.        
  20. }
  21.  
  22.  

but NGUITools.SetActive command enable only parent and not all child objects.

On checkbox is assigned UICheckboxControlledComponent for hide/show GUI groups and workls well, parent and child objects are hide/show.

It's strange.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: OnEnable/OnDisable
« Reply #1 on: September 16, 2012, 07:10:46 PM »
Scripts on disabled game objects can't receive events.