How do I make it so that my bullet doesn't just delete anything it touches and only deletes when it touches a certain layer?

public class Bullet : MonoBehaviour
{
public float life = 3;

void Awake()
{
    Destroy(gameObject, life);
}

void OnCollisionEnter(Collision collision)
{
    Destroy(collision.gameObject);
    Destroy(gameObject);
}

}

You can detect what layer is is colliding with like this:

 void Awake()
 {
     Destroy(gameObject, life);
 }
 void OnCollisionEnter(Collision collision)
 {
    
     // Check the value of your layer you want to detect in the layer manager (where the layers can be added and removed)
     if(collision.gameObject.layer == 1){

     Destroy(collision.gameObject);
     Destroy(gameObject);

     }
    
 }