Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: Roots on November 23, 2013, 12:29:41 AM

Title: Absolute position of a texture
Post by: Roots on November 23, 2013, 12:29:41 AM
Hi,

Is there an easy way to get the absolute position off a texture in NGUI? I have a 2D texture and want to know were exactly the user clicked. Maybe this is basic Unity stuff but was hoping someone tackled this already.

For the X i can simply take screenwidth - width of the texture, call this TextureX (as the texture is on a top-right anchor) and then use UICamera.lastTouchPosition.x - TextureX.

For the Y it is a bit trickier as the texture is not at the top OR bottom of the screen but somewhere in the middle.

Any help would be great.

Thanks
Title: Re: Absolute position of a texture
Post by: ArenMook on November 23, 2013, 08:27:40 PM
You shouldn't use just flat out position/localposition. Instead use UIWidget.localCorners. This gives you the local corner positions. Take the mouse position, ScreenToWorldPoint it so it's in world space, then widgetTransform.InverseTransformPoint it into local space. You now have a local rectangle, and a local point. The rest is easy.
Title: Re: Absolute position of a texture
Post by: Roots on November 24, 2013, 01:37:04 AM

Like this below?

transform.InverseTransformPoint(Camera.main.ScreenToWorldPoint(UICamera.lastTouchPosition))

Not seeing the expected result, i am getting the localCorners part, that seems to work fine but i think I am doing something wrong above?

Thanks
Title: Re: Absolute position of a texture
Post by: ArenMook on November 24, 2013, 01:40:34 AM
Camera.main is your game camera. You need to use the UI camera.