How to detonate an explosive

What is the best way to make a bomb explode? I want it to explode if something hits it or it hits something with high enough velocity, but not explode if you send it of by pushing or throwing it. If this makes sense?

What is the bet way to achieve this? In C#

I guess you could do something like this -

using UnityEngine;
using System.Collections;

public class Explosivethingy : MonoBehaviour {


    public float topvelocity; 
  
    void OnCollisionEnter2D(Collision2D collision){
        if(GetComponent<Rigidbody>().velocity.magnitude > topvelocity){
            //put your explode code here
        }
    }
}

if you want it to only explode when it “hits something with high enough velocity”

This may be of help to you -

BTW - I haven’t tested this code out, but it shouldn’t have any errors

Thanks, I’ll try playing around with that.