Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: darkloy on August 28, 2015, 03:59:43 AM

Title: Toggle click event called after addChild
Post by: darkloy on August 28, 2015, 03:59:43 AM
Hi,

I create prefab contain Panel with one toggle.
The toggle notify a public method :

  1.         public void toggleTest()
  2.         {
  3.                 Debug.Log ("Click on toggle");
  4.         }
  5.  

When i instantiate the prefab, the toggleTest method is called !
  1. void Start ()
  2. {
  3.         NGUITools.AddChild (nguiCamera.gameObject, panelWithTogglePrefab);
  4. }
  5.  

I use last version of NGUI

What the problem ?

Thank,

Laurent

Title: Re: Toggle click event called after addChild
Post by: Holy Manfred on August 28, 2015, 05:12:43 PM
It sounds like you used OnValueChange to notify your function. I think UIToggle always calls OnValueChange initially to set its starting state at the beginning.
After instantiating your prefab the toggle's initial value will be set and hence you'll get your toggleTest function called.