Please convert RaycastHit2D to RaycastHit 3d in unity c#..

Hi guys,
I need help in this line ,how i convert this to 3d, here it is

RaycastHit2D hit = Physics2D.Raycast(rayOrigin,Vector2.up*directionY, rayLength, collisionMask);
if(hit)
{
velocity.y = (hit.distance - skinWidth)*directionY;
rayLength = hit.distance;
}

plz convert this line for 3d raycasst.

Im not exactly sure what you mean by convert. Do you mean something like this?

        RaycastHit hitInfo;
        if(Physics.Raycast(rayOrigin, Vector3.up * directionY, out hitInfo, rayLength, collisionMask))
        {
            velocity.y = (hitInfo.distance - skinWidth) * directionY;
            rayLength = hitInfo.distance;
        }
1 Like

Ya like this only, but here why if condition came?

The if condition is to see if the raycast hits anything. No point trying to do something with the result if it’s null.