- Home /
[NGUI] How to I get the screen rect coordinates of a UI Drag Panel Contents?
I'm trying to get the rectangle (x, y, width and height) of a NGUI UIDragPanelContents component. The gameObject is inside a UIDraggablePanel in a 2D UI. The UIAnchor is set on Center with a half pixel offset.
Comment
Answer by Shaffe · Aug 03, 2012 at 12:14 PM
I found by myself the solution.
BoxCollider bc = GetComponent<BoxCollider> (); Vector3 pt = bc.transform.TransformPoint (bc.center);
float width = transform.localScale.x, height = transform.localScale.y;
pt = UICamera.currentCamera.WorldToScreenPoint(pt);
Rect rect = new Rect(pt.x - width / 2, pt.y - height / 2, width, height);
I don't have any material so the localScale works for me.
Your answer
Follow this Question
Related Questions
Possible to return the names of gameobjects inside a rect? 1 Answer
create a draw screen independent of resolution 0 Answers
Resize NGUI at Run Time 1 Answer
Android Screen Unresponsive to Touch After Many Activity Changes 0 Answers
Collider to Screen Space: Determining if it's Within a Rect 1 Answer