how do i make this shoot on collision?

How can i make this shoot on collision and keep on running the script even if you are not touching the object any more?

  //Attach to empty object, in front of barrel
 var projectile : Rigidbody;
  var speed = 20;
  var fireRate = .5;
 var mySound : AudioClip;
  function Update(){

  function Fire()
	var instantiatedProjectile : Rigidbody = Instantiate(
  projectile, transform.position, transform.rotation );
	instantiatedProjectile.velocity =
  transform.TransformDirection( Vector3( 0, 0, speed ) );
	Physics.IgnoreCollision( instantiatedProjectile. collider,
  transform.root.collider );

With a collider attached and the thing you want to hit having a collider and a rigidbody:

  function OnCollisionEnter(collision : Collision) {
       if(collision.gameObject.tag =="Whatever")

If the collider attached is a trigger:

 function OnTriggerEnter(other : Collider) {
       if(other.gameObject.tag =="Whatever")