Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: Game Whiz on August 05, 2012, 03:54:48 PM

Title: UIPanel/UIGrid add button dynamically
Post by: Game Whiz 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
Title: Re: UIPanel/UIGrid add button dynamically
Post by: ArenMook 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.
Title: Re: UIPanel/UIGrid add button dynamically
Post by: Game Whiz on August 05, 2012, 04:13:22 PM
Good guess :) It's working now. Thanks!