Author Topic: Toggle click event called after addChild  (Read 11013 times)

darkloy

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1
    • View Profile
Toggle click event called after addChild
« 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


Holy Manfred

  • Jr. Member
  • **
  • Thank You
  • -Given: 1
  • -Receive: 8
  • Posts: 71
    • View Profile
Re: Toggle click event called after addChild
« Reply #1 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.