Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: papatriz on February 26, 2014, 01:06:40 PM

Title: Strange issue with OnClick (and other mouse events as well) event
Post by: papatriz on February 26, 2014, 01:06:40 PM
Hello,

I have a ScrollView panel with buttons in the Grid inside. It is main screen of my education app, where user choose lesson.
Each button is 2D Sprite with attached scrollview script, and my own control script, which handle OnClick event and OnEnable event:
  1. void OnEnable ()
  2. {
  3.        if (Lesson.GetComponent<LessonControl> ().IsReached)
  4.                         {
  5.                             GetComponent<UI2DSprite>().sprite2D = Active;
  6.                         }
  7.                 else
  8.                         {
  9.                             GetComponent<UI2DSprite>().sprite2D = Locked;      
  10.                         }
  11. }
  12.  
  13. void OnClick ()
  14.         {
  15.                 Debug.Log ("CLICKED!");
  16.                 if (Lesson.GetComponent<LessonControl> ().IsReached) {
  17.                                                 GameObject.Find("MainControl").SendMessage ("StartLesson");
  18.                                                 Lesson.SetActive (true); }      
  19.         }

When some button have been clicked, I deactivate this panel and switch to main camera:
  1.         void StartLesson ()
  2.         {
  3.                 NGUITools.SetActive (MainScreen, false);
  4.                 MainCamera.active = true;
  5.         }
  6.  

After lesson is finished, I activate panel back in the same way:
  1. MainCamera.active = false;
  2. NGUITools.SetActive (MainScreen, true);

But after that the only one button stays clickable, all others stop to catch OnClick (and other mouse events - i tried to attach UIButton script to check it) event. I double check Z coord, widget depth, box colliders - all looks fine, and no visible difference between buttons.
Also, when I test it with two buttons - the first one stay working, when I added two more - the 3rd one...
Title: Re: Strange issue with OnClick (and other mouse events as well) event
Post by: ArenMook on February 26, 2014, 02:59:26 PM
Try enabling the Debug checkbox on the UICamera. It will give you an idea of what's under the mouse.
Title: Re: Strange issue with OnClick (and other mouse events as well) event
Post by: papatriz on February 26, 2014, 03:02:34 PM
Yes, I did it.
But unfortunately it also stopped work after re-activate panel
Title: Re: Strange issue with OnClick (and other mouse events as well) event
Post by: ArenMook on February 26, 2014, 03:06:00 PM
Wait, you're using Unity 2D sprites here... I don't remember if the event detection is currently correct for those in 3.5.1. Current Pro version of NGUI (partial 3.5.2) has the hit detection proper. Any particular reason you're using Unity 2D sprites? The Unity 2D system is missing some key important things in Unity 4.3, schedule to be addressed in 4.5/4.6.
Title: Re: Strange issue with OnClick (and other mouse events as well) event
Post by: papatriz on February 26, 2014, 03:42:34 PM
Heh, problem was not in unity sprites - I've tried to change it to ngui sprites but result was the same.
It was an issue with box collider on Grid component. After disabling it all started work as intend.