Author Topic: Leaderboard - Accessing labels of prefab and adding to UIGrid  (Read 2823 times)

singh029

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 28
    • View Profile
Leaderboard - Accessing labels of prefab and adding to UIGrid
« 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!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Leaderboard - Accessing labels of prefab and adding to UIGrid
« Reply #1 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";

singh029

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 28
    • View Profile
Re: Leaderboard - Accessing labels of prefab and adding to UIGrid
« Reply #2 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";