Author Topic: Drag and Drop problem  (Read 2405 times)

urban

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
Drag and Drop problem
« on: April 19, 2014, 08:26:24 AM »
HI,

I have created a inventory system using NGUI but i have a problem while dragging the item, the sprite doesnt not keep to the center of the mouse curser.

Here is a link to my script

http://pastebin.com/K8CTaUTZ

the code for the inventory works fine.

I do not use the uidragroot as that causes more problems
Here is a screen shot of the problem

https://www.evernote.com/shard/s225/sh/b1ef46de-559e-4041-afed-71bcb30dee3d/250298cf176802d8a1501b71019cb9e2

Please could you help.




ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Drag and Drop problem
« Reply #1 on: April 19, 2014, 11:10:51 PM »
You are setting "mTrans.localPosition = Input.mousePosition;" -- This is wrong. Input.mousePosition is in screen coordinates. Transform's localPosition is in local coordinates -- relative to the parent. You need to convert screen to world, then convert world to local using standard math functions (camera.ScreenToWorldPoint, transform.parent.InverseTransformPoint)

urban

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
Re: Drag and Drop problem
« Reply #2 on: April 20, 2014, 04:42:39 AM »
Thanks very much this solved the issue