How to return UI element at mouse with RayCast

Hi everyone,
So what I want to do is return the UI (Unity 4.6) element that the mouse is over when ever the following function gets called:

    bool isUIObjectAtMouse(out GameObject objectAtMouse)
        int layerMask = 1 << 5;
        Ray ray;
        RaycastHit hit;
        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        if (Physics.Raycast(ray, out hit, Mathf.Infinity, layerMask))
            objectAtMouse = hit.transform.gameObject;
            return true;
            objectAtMouse = null;
            return false;

But the problem is it never returns true. The elements do have 2DBoxColliders on them…
I’m quite a novice with regards to RayCasts so any obvious mistakes that I am doing would be really appreciated :slight_smile:

Use Physics2D instead of Physics :wink: