How do I create a raycast from the end of my gun to go wherever i have my gun pointed

I have a raycast script and i want to make it so that the ray gets casted from the end of my gun, so that when i click my mouse button the ray is created at the end of my gun and travel foward wherever my gun is pointed.

Here is my script:
var endBarrel :Transform;
var sound : AudioClip;

var TheDamage = 100;
var Effect : Transform;
var Enemy : GameObject[];




 
function Start() {



}
function Update(){
      var hit : RaycastHit;
     
      var ray =  Camera.main.ScreenPointToRay(Vector3(Screen.width*0.5, Screen.height*0.5, 0));
    if (Physics.Raycast (ray, hit, 100)) {
           hit.transform.SendMessage("ApplyDamage", TheDamage, SendMessageOptions.DontRequireReceiver);
    }
     
     


     
     if(Input.GetButtonDown("Fire1")){
        // you can use PlayOneShot to specify the sound...
        audio.PlayOneShot(sound);

        audio.Play();
    }

      
       
        
         
          
            if (Input.GetMouseButtonDown(0)){
          if (Physics.Raycast (endBarrel.position, transform.forward, 100))
          {
 
      
          
          
          
          
          
          }
      }
   }

Check out this answer here. I think this should help. To calculate direction, just subtract vectors from both ends of the gun.

That is assuming your gun is an actual object in the sceneā€¦

Try:

var endBarrel :Transform; 
var sound : AudioClip;
var TheDamage = 100;
var Effect : Transform;
var Enemy : GameObject[];
 
function Start()
{
 
}

function Update()
{
  var hit : RaycastHit;
 
  if(Input.GetButtonDown("Fire1"))
  {
    // you can use PlayOneShot to specify the sound...
    audio.PlayOneShot(sound);
 
    audio.Play();
  }

  if (Input.GetMouseButtonDown(0))
    {
      if (Physics.Raycast (endBarrel.position, transform.forward, hit, 100))
      {
        hit.transform.SendMessage("ApplyDamage", TheDamage, SendMessageOptions.DontRequireReceiver);    
      }
    }
  }
}