Welcome,
Guest
. Please
login
or
register
.
May 03, 2026, 07:54:36 PM
Home
Help
Search
Login
Register
Tasharen Entertainment Forum
»
Support
»
NGUI 3 Support
»
scroll view label child via script position problem
« previous
next »
Print
Pages: [
1
]
Author
Topic: scroll view label child via script position problem (Read 5046 times)
nitzamc
Newbie
Thank You
-Given: 1
-Receive: 0
Posts: 7
scroll view label child via script position problem
«
on:
August 29, 2014, 07:01:41 PM »
hey guys im creating multiplayer game and i am implementing ngui for menu where appears labels in a scrollview that show available server rooms.and i am instantiating a UILabel prefab it apears on UI Root & then i make it a child of scroll view and it's changing position to random numbers or i dont know what's wrong here is the script ... it may be hard coded,any help would be apreciated.btw im new
void
drawLobby
(
)
{
foreach
(
RoomInfo room
in
PhotonNetwork
.
GetRoomList
(
)
)
{
GameObject TempLabel
=
(
GameObject
)
Instantiate
(
roomListlabel
)
;
TempLabel
.
transform
.
parent
=
parentObject
;
TempLabel
.
GetComponent
<
UILabel
>
(
)
.
text
=
room
.
name
+
" "
+
room
.
playerCount
+
" / "
+
room
.
maxPlayers
;
TempLabel
.
transform
.
localScale
=
new
Vector3
(
1
,
1
,
1
)
;
//TempLabel.transform.position = new Vector3(-309, y, 0);
y
-=
40
;
}
Logged
ArenMook
Administrator
Hero Member
Thank You
-Given: 337
-Receive: 1171
Posts: 22,128
Toronto, Canada
Re: scroll view label child via script position problem
«
Reply #1 on:
August 30, 2014, 09:27:50 AM »
Never use Instantiate() with UI elements. Use NGUITools.AddChild. It sets the parent for you, resets the position/scale, and even sets the layer properly.
Logged
nitzamc
Newbie
Thank You
-Given: 1
-Receive: 0
Posts: 7
Re: scroll view label child via script position problem
«
Reply #2 on:
August 30, 2014, 02:48:37 PM »
it automaticaly sets the parent? or the parent is the gameobject that script is attached?
Logged
ArenMook
Administrator
Hero Member
Thank You
-Given: 337
-Receive: 1171
Posts: 22,128
Toronto, Canada
Re: scroll view label child via script position problem
«
Reply #3 on:
August 31, 2014, 02:53:01 PM »
NGUITools.AddChild(parent, prefab);
You could have just looked at the function and answered your own question. :|
Logged
nitzamc
Newbie
Thank You
-Given: 1
-Receive: 0
Posts: 7
Re: scroll view label child via script position problem
«
Reply #4 on:
September 10, 2014, 03:25:40 PM »
you are right... sorry
i have another problem i uploaded images so i can give u understand because i'm not good english speaker...
so i need it to appear like this in the scroll view after instantiation (addchild)
if i drag the label prefab and drop it as a child in hierarchy it automaticaly apears like this,and that is excactly my goal.but via script it appears like this
«
Last Edit: September 10, 2014, 03:55:55 PM by nitzamc
»
Logged
ArenMook
Administrator
Hero Member
Thank You
-Given: 337
-Receive: 1171
Posts: 22,128
Toronto, Canada
Re: scroll view label child via script position problem
«
Reply #5 on:
September 11, 2014, 01:45:24 AM »
Look at the transform position. It's (-116, 208, 0) in the first picture, and (0, 0, 0) in the second. When you do AddChild(), it resets the position. You need something that positions the content properly for you -- like a UIGrid for example.
Logged
nitzamc
Newbie
Thank You
-Given: 1
-Receive: 0
Posts: 7
Re: scroll view label child via script position problem
«
Reply #6 on:
September 11, 2014, 08:10:35 PM »
@ArenMook although i've added UIGrid & nothing changed i solved it via script , would be better if scripting doesn't involved
Logged
Print
Pages: [
1
]
« previous
next »
Tasharen Entertainment Forum
»
Support
»
NGUI 3 Support
»
scroll view label child via script position problem