2d Raycast follow a UI element - not mouse position.

All over the web - hits are about mouse position. I need a raycast that follows a UI element in 4.6 gui canvas. I wrote this code, but it seems to not be working.

RaycastHit2D hit = Physics2D.Raycast
            (Camera.main.ScreenToWorldPoint(customCursors[0].transform.position), Vector2.zero);

Do you need a raycast to 3d world from UI or UI element to handle UI events like it’s a cursor?

I use this code (though its ordinary raycast, not 2d, but I think it should work)

        RaycastHit hit;
        Ray ray = raycastCamera.ScreenPointToRay(new Vector3(pointerGraphics.transform.position.x, pointerGraphics.transform.position.y, pointerGraphics.transform.position.z));
        ray.direction = ray.direction += (Random.insideUnitSphere / 100) * equippedWeapon.fireSpread;

Where pointerGraphics is an UI object which I control through script.

If you want an UI object to work as a mouse cursor, try this solution - though I can’t guarantee if it will work on 4.6 (and it’s broken on 5.5 currently)