Welcome,
Guest
. Please
login
or
register
.
June 14, 2026, 10:57:04 PM
Home
Help
Search
Login
Register
Tasharen Entertainment Forum
»
Support
»
NGUI 3 Support
»
Best way to anchor a widget to an object in the scene?
« previous
next »
Print
Pages: [
1
]
Author
Topic: Best way to anchor a widget to an object in the scene? (Read 3989 times)
laurentl
Full Member
Thank You
-Given: 0
-Receive: 0
Posts: 188
Best way to anchor a widget to an object in the scene?
«
on:
June 10, 2013, 01:53:28 PM »
I see that anchor only attach to camera, panels and widgets. Is there a script to attach to a 3D object so that the health bar follows the object?
Logged
McDROID!
http://www.mcdroidgame.com/
ArenMook
Administrator
Hero Member
Thank You
-Given: 337
-Receive: 1171
Posts: 22,128
Toronto, Canada
Re: Best way to anchor a widget to an object in the scene?
«
Reply #1 on:
June 10, 2013, 02:42:02 PM »
No, that's what UIFollowTarget does from the HUDText add-on. Also it's just 3 lines of code anyway.
Logged
laurentl
Full Member
Thank You
-Given: 0
-Receive: 0
Posts: 188
Re: Best way to anchor a widget to an object in the scene?
«
Reply #2 on:
June 10, 2013, 02:47:16 PM »
I'm actually using it for context menu
I tried this but the UI gets sent really far.
void
LateUpdate
(
)
{
transform
.
position
=
cam
.
WorldToScreenPoint
(
target
.
position
)
;
}
Logged
McDROID!
http://www.mcdroidgame.com/
ArenMook
Administrator
Hero Member
Thank You
-Given: 337
-Receive: 1171
Posts: 22,128
Toronto, Canada
Re: Best way to anchor a widget to an object in the scene?
«
Reply #3 on:
June 10, 2013, 11:23:19 PM »
That's because WorldToScreenPoint gives you screen space coordinates, and then you just go and assign them to transform.position which is in world space coordinates.
Logged
Print
Pages: [
1
]
« previous
next »
Tasharen Entertainment Forum
»
Support
»
NGUI 3 Support
»
Best way to anchor a widget to an object in the scene?