Author Topic: Initialize Drag and Drop per script  (Read 7162 times)

Malzbier

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 93
    • View Profile
Initialize Drag and Drop per script
« on: July 20, 2012, 03:20:43 AM »
Hallo, im currently trying to to make a drag and drop action be initialized by a script.

My scenario:

Press on Button -> Instantiate prefab with drag and drop script -> Drag and drop is enabled for the new script and the object is moving with the dragging input.

How to enable the the last step?

Calling OnPress(true) (now public) in the dragdrop script does not do the trick.

Thanks for reply

PhilipC

  • Guest
Re: Initialize Drag and Drop per script
« Reply #1 on: July 20, 2012, 09:41:27 AM »
Try manually setting the UICamera.selectedObject to be the object you want to drag around.

Malzbier

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 93
    • View Profile
Re: Initialize Drag and Drop per script
« Reply #2 on: July 23, 2012, 03:27:22 AM »
Setting the UICamera.selectedObject to be the object i want to drag around does not work at all.
The problem seems to be that a button is directly under the the generated drag able object.

Dragging works fine if i deactivate the button after creation and press again on the drag able object.

The key is that i need the drag to run directly with the first press / touch.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Initialize Drag and Drop per script
« Reply #3 on: July 23, 2012, 05:37:52 AM »
Selecting the object isn't enough. You need to give it touch focus. UICamera.currentTouch.pressed = yourNewGameObject.

Malzbier

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 93
    • View Profile
Re: Initialize Drag and Drop per script
« Reply #4 on: July 23, 2012, 07:07:55 AM »
Thanks to both of you: both tips together done the trick.