Use ray cast against objects but avoid colliding against other objects

I am trying to make a fruit ninja rip off.

My issue is where I don’t want the fruits and bombs to collide but still want to be able to raycast onto them.

I don’t know if there some way to use layers but there is nothing I can find about it.

Assign different layers to the fruits and the bombs and use the collision matrix to avoid them to collide between each other.

Link to documentation

I’m not quite sure what it is you want to do but if you want to use a layer mask do the following :

public var lmPlayer : LayerMask;

function subRaycast() {

    var hit : RaycastHit;
    var fRaycast_Distance : float = 5.0;
    
    //Raycast from current position of your object in forward direction.
    if (Physics.Raycast (transform.position, transform.forward, hit, fRaycast_Distance, lmPlayer)) {
    
        //If object is found...
        if (hit.collider != null) {

            //Do your code...
        }
    }
}

Use the public layer mask as you will be able to pick what to exclude easily from the drop down menu in the inspector window.
Apologies for any code formatting issues, I’m having a nightmare with this, nothing works…