Author Topic: Drag Object does not work  (Read 4095 times)

chayanvinayak

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 6
    • View Profile
Drag Object does not work
« on: June 05, 2014, 11:06:17 PM »
I am trying to create a draggable object and for that I have :
1. Created a sprite
2. Added Box-collider on sprite
3. Added "Drag Object" Script on sprite( attached the properties object itself and UI-panel which is UI-Root)
4. Made sure Camera has "UI camera" attached with it.

But I can't drag the object.
Is there anything that I am missing ?

Thanks

dipu5683

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 27
    • View Profile
Re: Drag Object does not work
« Reply #1 on: June 06, 2014, 01:48:31 AM »
make sure about the box collider width & height.
add UIDragDropItemScript on to it.



ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Drag Object does not work
« Reply #2 on: June 06, 2014, 02:44:03 AM »
When you create your first sprite, a UI camera is created for you. There is no need to attach anything. The first 3 steps are enough to make it possible to drag the object around. Enable Debug on the UICamera to see what's getting the events. If nothing does, check the FAQ.

chayanvinayak

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 6
    • View Profile
Re: Drag Object does not work
« Reply #3 on: June 06, 2014, 01:02:57 PM »
Thanks ArenMook and dipu5683!

I found the problem ( not the solution :) )

I have three cameras in the scene. Camera1 and Camera2 are Clear Flags=Depth Only so that their view can be overlapped on Camera3  :
Camera 1 : Camera that is created by NGUI (when I created first sprite) and this sees all the 3d-GUI. I have 3d-objects and sprites for GUI.
Camera 2 : Camera that sees the game-play element which in this case is draggable object.

Camera 3 : Back camera that sees background-image.

Camera 1 sees a big button that covers the complete screen when you click on that button, it disables Camera1 and enables Camera2 so that you can start playing the game.



Problem : Problem is that even when I disable Camera1 (NGUI camera) and switch to Camera2. Camera1 still raycasts on big-button that covers the draggable object and that is why it never picks draggable object ( which I am able to see in Camera1-Debug )



NGUI camera raycasts on the elements that are visible to it evenwhen it is disabled which blocks the click-detection on other elements visible by another camera


I appreciate your help!
Thanks

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Drag Object does not work
« Reply #4 on: June 06, 2014, 09:45:29 PM »
You need to disable the button, not the camera that sees it. Or at least its UIRoot.

chayanvinayak

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 6
    • View Profile
Re: Drag Object does not work
« Reply #5 on: June 07, 2014, 12:01:56 AM »
I am also seeing inconsistencies with NGUI camera click detection. Sometimes, it detects click on some objects and doesn't detect on others, even if they belong to same layer.

If adding a collider of proper size is the only requirement for receiving the raycast collision then I have it.
Is there anything else that is need for a sprite to be detected by a camera raycast ?

chayanvinayak

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 6
    • View Profile
Re: Drag Object does not work
« Reply #6 on: June 07, 2014, 02:15:51 AM »
Watch this Video : https://www.youtube.com/watch?v=wUsZiMhdh7g

Initially my camera is at -121 rotation and It can detect raycast hit on elements on screen then I turn the camera to 0 and it stops detecting hit.
After that, I try rotating the camera back and forth and then I wait for a while and NGUI camera itself start detecting raycast hit on the element which it was not detecting previously.


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Drag Object does not work
« Reply #7 on: June 07, 2014, 09:03:59 PM »
Look at the transform of your camera. Position of over 7000? Scale of 238? Where is all this coming from? Set them to some sane values (like position 0, scale 1) and you might have better luck. Note that your min clip is 0.3 and max is 1000. Again -- these are default values, and unless your UI extends from 0.3 units to 1000 units, you're not doing it right. Saner values to use here would be 0.3 to 10, for example.

chayanvinayak

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 6
    • View Profile
Re: Drag Object does not work
« Reply #8 on: June 07, 2014, 09:39:27 PM »
Thanks ArenMook!

The reason why I have massive-scale values is because when I create UIRoot it itself gets a scale value of .000416 ( which I can't change ) and to compensate child's scale value  Unity makes it huge value and that is also the reason of having massive translation values.

Is there any way I can reset UIRoot scale ?

I will try to reduce the clipping plane values and see if it makes any difference.

Thanks again!


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Drag Object does not work
« Reply #9 on: June 07, 2014, 09:49:06 PM »
UIRoot is small intentionally. It's 2 / Screen.height by default. When adding children to it, select the UIRoot and use the ALT+SHIFT+N shortcut. The camera should have already been a child of it because when you create a UI it adds a camera for you, so not sure why you had to create one of your own.