Tasharen Entertainment Forum
Support => NGUI 3 Support => Topic started by: alexh0101 on September 01, 2014, 02:19:14 PM
-
I have a prefab that has a child. This child has UILabel, Tween Position and Tween Alpha attached to it.
I set it to move from (0,0,0) to (0,2,0). These are the local position of the label.
When I drag and drop and instance of that prefab in the scene and hit play, it works as expected.
But when my game uses the method Instantiate(), the spawned labels appear at GLOBAL position (0,0,0).
In this case, am I supposed to use TweenPosition.Begin() as suggested in another thread?
I tried using it but I couldn't get it to work.
Thanks in advance
-
First, never use Instantiate. Use NGUITools.AddChild.
And yes, ideally use TweenPosition.Begin to start your tween.
-
Hi there, thanks for your response.
I actually want to spawn that label right when the parent object is destroyed (I'm doing a scoring label like "+10").
Adding a child to that gameObject wouldn't work in that case since the gameObject gets destroyed.
Is there an alternative, so that I can spawn that prefab exactly where that object was destroyed?
-
Just forward the global position of the original object to whatever spawns the label, and set its .position to that.
-
But the problem is that the coordinates of the original object are something like (0,-5,0) but the coordinates of my tween label should be approx (0,-2000,0) in order to appear at the same place as the (0,-5,0).
I'm getting mixed up with screen coordinates and world coordinates.
Do I have to convert world coordinates to screen coordinates and set the "from" and "to" via scripting?
Thanks a lot
-
You are confusing local and world coordinates.
transform.position = world
transform.localPosition = local
Look in NGUIMath. It adds extension methods to transform -- OverlayPosition. It does all the necessary math inside.