Author Topic: Cannot get touch.position working for UISprite  (Read 1844 times)

Jofator

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 9
    • View Profile
Cannot get touch.position working for UISprite
« on: May 15, 2014, 08:34:29 AM »
Hi there,
I have Bottom-Left Anchored UISprite object.
I want to identify Touch position over UISprite.
So I used nguiCamera.WorldToScreenPoint(sprite.worldCorners[index]); to get sprite screen position to detect touch and sprite collision.
In UnityEditor it works perfect, but once deployed to S3 and/or iPhone5
it detects X collision out of sprite gfx - about 10-20% moved to center of screen (see attachment)
Y collisions works fine.

What's wrong?
Thanks
Jofator


PS: Using NGUI 3.5.9 and FixedSize UIRoot.
Jofator

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Cannot get touch.position working for UISprite
« Reply #1 on: May 15, 2014, 12:03:02 PM »
What version of Unity?

Jofator

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 9
    • View Profile
Re: Cannot get touch.position working for UISprite
« Reply #2 on: May 15, 2014, 12:32:24 PM »
Latest Unity 4.3.4
Jofator

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Cannot get touch.position working for UISprite
« Reply #3 on: May 16, 2014, 12:29:55 PM »
I would suggest changing your PC build's aspect ratios to see if you can reproduce it there (or easier still: just aspect ratios in the editor).

WorldToScreenPoint is just a Unity function. You pass sprite.worldCorners[index] to it -- not sure what this 'index' is, but there are 4 corners total. Sprite's world-space position would be sprite.transform.position, and center would be Vector3.Lerp(corners[0], corners[2], 0.5f).