1
Support / Re: UI events not responding correctly
« on: July 29, 2013, 07:21:28 pm »Hi,
Yes, the code is working as expected, in that once you click down with the mouse button you are no longer 'hovering'. Also the OnRelease will return the item you originally clicked down on.
I see. I was assuming that the behavior of the event was only triggered by exiting the collider boundaries.
If you are trying to create a drag-and-drop effect, would it be possible to add something to your script like this (in the Update function):
if(Input.GetMouseButton (0))
{
Ray ray = gameCam.ScreenPointToRay(Input.mousePosition);
RaycastHit[] hits = Physics.RaycastAll(ray, Mathf.Infinity);
Debug.Log(hits.Length);
foreach (RaycastHit hit in hits)
{
// Do something
}
}
So basically this will return all colliders the ray hits whilst the mouse button is held down (although the colliders aren't guaranteed to be in any particular order).
This is definitely possible (adding a layer mask to the raycast to make sure it is only the UI returned). However, this defeats the purpose of using the 2dUI event system to interact with UI objects. I was hoping to avoid it.
Thanks for the clarification.