- Home /
NGUI - Vector 3 Position different from position
I've been trying to set a vector3 position in a new array and set the positions in code, yet when I have a transform object move to the location, it jumps to a different one:
public Vector3[] mousePosition;
mousePosition = new Vector3[2];
mousePosition[0] = new Vector3(0.0F, -37.0F,0.0F);
fieldmouse.transform.position = mousePosition[0];
I'm using C# and just don't get it. The code should set the Y position to -37. Yet the transform is suddenly at -6735 instead.
it works when i try it in a new C# script, perhaps you can provide some more information, such as what is fieldmouse exactly? i simply set it as a cube gameobject and it works.
could you post your entire script ?
im freaking awesome if this solves it by the way.
-37 is 37 meters or a really long ways below the terrain height which is 0.
Your mouse is below the terrain and if your field mouse has a rigidbody with gravity enabled it is freefalling until it arrives at whatever unitys editor rockbottom is?
No, it's a sprite powered by NGUI, so I'm guessing the problem lies there.
Answer by whydoidoit · Nov 11, 2012 at 06:13 PM
With NGUI you need to use localPosition - global positions are all screwy because of the number of scaled parents that NGUI uses. Basically NGUI objects are placed on pixel boundaries - but your global position is just some real world thing.
Try settings the localPosition instead.
Be aware that the position you see in the inspector is the localPosition.
I tried the localPosition with no success. Like whydoidoit said, that number in the inspector is the one off.
If you do this:
fieldmouse.transform.localPosition = mousePosition[0];
The the number in the inspector should read: 0.0F, -37.0F,0.0F
I ran a debug.log to get a print out and that's correct. It seems like the problem is located when it's forced to move. I've figured out a solution.