Author Topic: Get texture's pixel coordinates when touching a UITexture?  (Read 2649 times)

Joe @ ByDesign Games

  • Guest
Get texture's pixel coordinates when touching a UITexture?
« on: June 21, 2013, 12:14:16 AM »
Have a need to get a texture's pixel coords from touching a UITexture.

Have tried a variety of approaches to no result.

Anyone know how to do this reliably?

Joe @ ByDesign Games

  • Guest
Re: Get texture's pixel coordinates when touching a UITexture?
« Reply #1 on: June 21, 2013, 02:21:47 PM »
Adding, have also tried using RaycastHit.textureCoords but that requires a mesh collider (no other collider is supported) and considering UITexture doesn't expose it's mesh, it's not working.

How else to do this?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Get texture's pixel coordinates when touching a UITexture?
« Reply #2 on: June 22, 2013, 06:07:15 AM »
Math. You know a 3D click point on the collider. Use the widget's transform.InverseTransformPoint to make it local. Divide by width/height. May or may not have to flip the Y (1 - y).

Joe @ ByDesign Games

  • Guest
Re: Get texture's pixel coordinates when touching a UITexture?
« Reply #3 on: June 22, 2013, 06:18:39 AM »
Ahh right, infer from the collision point; for some reason thought texture coords couldn't be derived that way.

Thanks Michael!