Make tranform follow raycast

Hello, I’ve been trying to make a weapon script which fires a projectile (prefab) straight forward.I added to the bullet the first script shown here.And the second one to the main camera.The problem is that the gun doesn’t shoot straight forward.I mean it shoots straight but in small distances it looks…crap.How can I make it so it follows the hit point of the raycast.I placed my attempt below.

Script 1:

var bulletSpeed : float = 20;

function Update () 
{	
	transform.Translate(Vector3.forward * bulletSpeed * Time.deltaTime);
}

Script 2 :

var hit : RaycastHit;
	var forward = transform.TransformDirection(Vector3.forward);
	
	if(Physics.Raycast(transform.position, forward, hit, rayLength))
	{
	
	if(Input.GetButtonDown("Fire1") && canShoot==true && clip > 0)
    {
        var rocketInstance : Transform;
        rocketInstance = Instantiate(rocketPrefab, barrelEnd.position, transform.rotation);
        rocketPrefab.LookAt(hit.point);
        w();
        gun.animation.Play("Shoot");
        audio.PlayOneShot(soundEffect);
        clip -= 1;
    }
}

Thank you for your time,please help me!

Your problem is that you are using LookAt() on the wrong object. You want to do the LookAt on the rocketInstance.

rocketInstance.LookAt(hit.point);