Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: singh029 on February 26, 2014, 11:26:56 AM

Title: Leaderboard - Accessing labels of prefab and adding to UIGrid
Post by: singh029 on February 26, 2014, 11:26:56 AM
Hi how do i access and edit a specific label in a prefab and then add it to the UIGrid?

I want to create a leaderboard and each prefab contains a rank label, name label, and score label.

I referenced this post and found how to add children to a parent.
http://www.tasharen.com/forum/index.php?topic=7418.0

But how do i access and edit each label and then add it to the UIGrid

Thank you!
Title: Re: Leaderboard - Accessing labels of prefab and adding to UIGrid
Post by: ArenMook on February 26, 2014, 02:16:17 PM
Dirty way? transform.FindChild("name of your label").GetComponent<UILabel>().

Clean way? Create a script attached to your prefab with public references to the labels you want to edit. You can then GetComponent<YourScript>().headerText = "Whatever";
Title: Re: Leaderboard - Accessing labels of prefab and adding to UIGrid
Post by: singh029 on February 26, 2014, 03:25:40 PM
I seeeeee! thank you!

So if i wanted to change the text of one of the labels, then i would do something like

var name = transform.FindChild("username").GetComponent<UILabel>();

name.text = "ArenMook";