Author Topic: Scrollview with clickable buttons in it  (Read 5798 times)

Nubeh

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 41
    • View Profile
Scrollview with clickable buttons in it
« on: October 29, 2013, 05:34:41 AM »
I'm trying to build a scrollable list with some buttons in it but I ran into a weird issue: my buttons are not clickable. For some reason the outline panel behind the buttons grid gets the collider hit all the time and I don't know why.

I have buttons in other parts of the scene and they work fine...the only difference with the buttons I have in the scrollview is that those buttons have the UIDrag Panel Contents script attached so that they can be used to drag the panel.

Did someone managed to make something like this and make it work?

Thanks

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: Scrollview with clickable buttons in it
« Reply #1 on: October 29, 2013, 09:13:06 AM »
Set the depths right. The buttons should be above the background one.

Nubeh

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 41
    • View Profile
Re: Scrollview with clickable buttons in it
« Reply #2 on: October 29, 2013, 10:02:17 AM »
yeah, stupid me...I did set the buttons depth correctly but the scrollview object containing them had depth 0...I just noticed.

Thanks anyway! ;)

Nubeh

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 41
    • View Profile
Re: Scrollview with clickable buttons in it
« Reply #3 on: October 30, 2013, 04:00:21 AM »
umm...no the problem isn't fixed :(. So weird...I put the scrollview object at a depth bigger than the background and it was working...then I changed the scrollview to scroll vertically rather than horizontally and now it doesn't work anymore...the buttons colliders seem to not get any click. I made a big square object as button and I parented a background, 2 labels and a sprite image. Not sure if the parenting so many object might cause the problem?

I tried to put just the button and the background as elements in the scrollview but also with that, no hit :(

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Scrollview with clickable buttons in it
« Reply #4 on: October 30, 2013, 05:27:14 AM »
First of all, make sure you're using the latest version of NGUI because depth & raycast handling has changed drastically in the last few versions. Second, ensure that your UICamera is set to UI mode. Lastly, enable debugging on the UICamera. It will give you an idea of what the mouse is hovering over.

Nubeh

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 41
    • View Profile
Re: Scrollview with clickable buttons in it
« Reply #5 on: October 30, 2013, 05:41:45 AM »
I found out what my problem was...to avoid having a tap trigger a collision with both the GUI elements and the game I made all my elements in the GUI be part of a 2D GUI layer. When I added the elements to my scrollview I forgot to set their layer and they were set to Default and that's why there was no hit event :(

I'm not sure if I have to still but the gui elements on their own layer with the new version of NGUI or if there's a way to tell all the elements to not let a tap affect what's behind them.

Thanks

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: Scrollview with clickable buttons in it
« Reply #6 on: November 10, 2013, 08:23:06 AM »
Keep GUI elements in their own layer, with their own camera, and make the main camera not see that layer.