Issue with detecting 2 objects using Raycast2D & Swipe

I’m at a loss on this issue.

Basically on mouse movement I want to detect if I pass over two colliders, this works but if I move the mouse quickly only the first collision is detected.

Any ideas?

if (Input.GetMouseButton(0))

{

RaycastHit2D hit = Physics2D.Raycast(mainCamera.ScreenToWorldPoint(Input.mousePosition), Vector2.zero);

if (hit)
{
    if (hit.collider.tag == "validTag")
    {
        if (firstCollider = null)
        {
            Debug.Log("Hit First Collider");
            firstCollider = hit.collider;
        }
        else
        {
            if (hit.collider != firstCollider)
            {
                Debug.Log("Hit Second");i
            }
        }
    }
}

}

Hi, most likely what happens is just that you won’t hit your target when making too fast movement with your mouse.

You check your hits every frame; If you move mouse in fraction of second to other side of screen, there’s no guarantee that you will hit every pixel between start and end of sweep without specialized solution. If your screen drawing update is 30FPS and each frame where hit is checked does not hit that object, you missed it.