Author Topic: UIPanel/UIGrid add button dynamically  (Read 2669 times)

Game Whiz

  • Guest
UIPanel/UIGrid add button dynamically
« on: August 05, 2012, 03:54:48 PM »
Hi,

I've opened up example 7, created a prefab out of the only button there ( Button (Click Me) ), and then in runtime, dragged the button prefab into the UIGrid, hitting repositionNow to reposition the newly added button. All panels are marked as non static.

It worked for the first instance of the button I dragged in. When I added the second, it apparently worked, but both buttons stopped responding to input. When I added the third, the two first buttons started responding to input, but the third one didn't.

I then wrote a small coroutine that added buttons via NGUITools.AddChild(gameObject,prefab) and got the same results.

Any idea on what might be going on?

What's the preferred way to dynamically add buttons to a UIGrid inside a UIPanel?

Alex

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIPanel/UIGrid add button dynamically
« Reply #1 on: August 05, 2012, 04:11:25 PM »
My guess -- your background and your buttons all have colliders that are on the same Z, so Unity's raycasts may or may not hit what you expect.

Game Whiz

  • Guest
Re: UIPanel/UIGrid add button dynamically
« Reply #2 on: August 05, 2012, 04:13:22 PM »
Good guess :) It's working now. Thanks!