- Home /
Moving an NGUI component to overlay game object.
I have little NGUI component I want to move (Around the Centre anchor) to be on top of a "selected" game object. But I can't seem to get the actual transformation correct as it ends up being all over the place.
What is wrong with this code?
public void Display(Vector3 pos)
{
// Enable select
selectUI.SetActive(true);
// Get screen location of node
Vector3 screenPos = Camera.main.WorldToScreenPoint(pos);
// Move to node
selectUI.transform.position = screenPos + new Vector3(Screen.width / 2, Screen.height/2, 0);
}
Answer by MorphingDragon · Jul 06, 2013 at 03:36 PM
For those who are interested NGUI's internal points don't seem to be in a different space that what's in the editor. I fixed it by changing it the code to this:
public void Display(Vector3 pos)
{
// Enable select
selectUI.SetActive(true);
// Get screen location of node
Vector2 screenPos = Camera.main.WorldToScreenPoint(pos) ;
// Move to node
selectUI.transform.position = camera.ScreenToWorldPoint(screenPos);
}
Just to clarify, the first camera (Camera.main) is 3D camera, the second is a UICamera.
Your answer
Follow this Question
Related Questions
Converting world coordinates to screen coordinates 1 Answer
NGUI/GUI button emulating Keyboard letter press 1 Answer
Wrong WorldToScreenPoint converting (not inverted y) 0 Answers
How to change the arrpearance of the mobile keyboard 1 Answer
How to implement Platoevolved's In app billing with NGUI? 0 Answers