Author Topic: Add offset to dragging  (Read 2051 times)

apple741

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 17
    • View Profile
Add offset to dragging
« on: October 10, 2014, 11:42:05 AM »
Hello,

I am trying to add an offset to my drag using this code: http://pastebin.com/dV8iSdpj

The problem is that it doesn't seem to have any effect?

Thanks!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Add offset to dragging
« Reply #1 on: October 11, 2014, 04:17:11 AM »
Dragging the object changes its position. If you want it to be offset, offset its child instead.

apple741

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 17
    • View Profile
Re: Add offset to dragging
« Reply #2 on: October 12, 2014, 03:28:20 PM »
Hi Aren,

That sounds like exactly what I'm looking for! I'm afraid I'm not entirely sure what you mean?

I just tried moving the texture to a separate game object as a child, where the parent game object was just be an empty collider but that didn’t seem to create an offset either - using the code shown previously.

Thanks!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Add offset to dragging
« Reply #3 on: October 13, 2014, 03:00:43 AM »
You are probably overthinking it.

Game Object (dragged object)
- Child object (offset position)

The offset is just your transform position. Move it around.

apple741

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 17
    • View Profile
Re: Add offset to dragging
« Reply #4 on: October 16, 2014, 08:06:13 AM »
Hi Aren,

If I have an empty game object with a collider on it and then a child offset with my actual UITexture people will end up clicking on the texture which has no collider rather than the parent with one?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Add offset to dragging
« Reply #5 on: October 17, 2014, 04:35:32 AM »
All events go to colliders, not widgets. However since your collider is on a game object rather than a widget, its depth is undefined -- it will use the highest depth of its child widgets. It's best to use an invisible widget instead (ALT+SHIFT+W)