Author Topic: OnClick issue  (Read 2995 times)

Tomleung

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 44
    • View Profile
OnClick issue
« on: May 25, 2014, 04:30:28 AM »
How can I do if I want the onclick function happen on the gameobjects,

which means that if I click on one gameobject, that do something.

How can I implement onclick function on this.

It is because I have tried to add UIcamera on Main Camera, add box collider with trigger on the gameobject and put a script that has OnClick function inside, but it does not work properly, it seems that only a few location I clicked on and so the onclick event begin.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: OnClick issue
« Reply #1 on: May 25, 2014, 08:08:56 PM »
What you did is all you need to do. Just make sure the event mask is set up correctly on the UICamera, and the event type is set to World (assuming you're using 3D colliders).

Tomleung

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 44
    • View Profile
Re: OnClick issue
« Reply #2 on: May 25, 2014, 11:40:27 PM »
However, I use the drag drop system on that too, I have tried to set the event type to be world but when I use the drag drop system, it seems that I can drag the icon only outside the grid. It is so strange.

Moreover, I have set a dragdropsurface on one place but I don't know why I can only drag and drop my items on only certain location of that surface. Quiet strange also. If I change my location and so drag and drop my items on the location of the surface that originally unable to drop the items on, it would successfully drop on the surface. It is very strange.
« Last Edit: May 26, 2014, 12:18:15 AM by Tomleung »

Tomleung

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 44
    • View Profile
Re: OnClick issue
« Reply #3 on: May 26, 2014, 02:31:17 AM »
I think I almost got the problem here.

If something has collider is near the drag drop surface, it has difficulties to detect the valid surface if I want to drag and drop items on the surface. However I don't how to fix it and it is impossible to take out that something and its collider too. So it is the tough probelm.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: OnClick issue
« Reply #4 on: May 26, 2014, 10:48:37 PM »
Events in NGUI arrive on the collider with the highest depth first in case of UI-based events (event type set on UICamera). If it's world-based, then it's all about the distance from the camera to the point of intersect (read: adjust the collider's Z position).

Tomleung

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 44
    • View Profile
Re: OnClick issue
« Reply #5 on: June 01, 2014, 01:08:57 PM »
Events in NGUI arrive on the collider with the highest depth first in case of UI-based events (event type set on UICamera). If it's world-based, then it's all about the distance from the camera to the point of intersect (read: adjust the collider's Z position).

How if it is 3D UI based?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: OnClick issue
« Reply #6 on: June 01, 2014, 05:36:42 PM »
3D UI is still UI. It's based on depth.

Tomleung

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 44
    • View Profile
Re: OnClick issue
« Reply #7 on: June 02, 2014, 03:12:26 AM »
In your example of Drag Drop Scene, I can drag items on the surface and it is 3D UI.

Situation 1: When I put another Drag Drop Surface quite near this surface, the Drag Dop Detection would be a big problems.

Situation 2: When I change the event type to World-based, it would have a problem on the Grid that I can not drag the icons properly on that and you can try it as well.

How to avoid the above problems and eventually successful in Drag Drop System?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: OnClick issue
« Reply #8 on: June 02, 2014, 10:52:18 PM »
The main camera is using the 3D World event type, not UI, and this is the camera that sees the drop surface (the cube). Note that the cube is a 3D world object. It's not a UI element.

Don't use World event type with UI. I don't know how else to explain it. UI = UI. World = World. If you use World event type with UI elements, events won't work properly. If you use UI type events with world objects, events won't work properly either. Right tool for the right job.