code for destroying an object when shot with certain object

ok so i am making a first person shooter game in with you shoot color objects with the right color beam… my question is how would i set up the code so that these objects are destroyed when shot with the right color?

Add this script to every Object

    function OnCollisionEnter(collision : Collision) {

    if(collision.gameObject.renderer.material == gameObject.renderer.material){
Destroy(collision .gameObject);
Destroy(gameObject);
}

}