Author Topic: NGUI OnDrag Question  (Read 4160 times)

remmbermytitans

  • Guest
NGUI OnDrag Question
« on: July 21, 2013, 04:55:05 AM »
Hey everyone, I looked around for an answer to this question but couldn't find anything. I have an object that uses OnDrag, and I want to have the object follow a user's finger on a device. What's the best way to do that? I tried a few different things, but nothing seemed to work correctly. Any thoughts?

  1. void OnDrag(Vector2 d)
  2. {
  3.       transform.localPosition = new Vector3(UICamera.lastTouchPosition.x - Screen.width/2, UICamera.lastTouchPosition.y - Screen.height/2, 0);
  4. }

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUI OnDrag Question
« Reply #1 on: July 22, 2013, 04:39:24 AM »
Why don't you just look at the drag & drop example that comes with NGUI? It does exactly this.

remmbermytitans

  • Guest
Re: NGUI OnDrag Question
« Reply #2 on: July 22, 2013, 04:58:12 PM »
I did look at the example, but it seems to me that the example only allowed drag objects that are within a grid. What I'm HOPING to do, is to have an object be "picked up" by touch and drop it anywhere on screen. Perhaps I am wrong, but is that the case?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUI OnDrag Question
« Reply #3 on: July 23, 2013, 05:20:22 AM »
The grid is just how I chose to organize them. They don't need to be in a grid.