Problem With Ray

I am trying to make various guns in unity, I have made pistols and macine guns but right now im trying to make a shotgun. I want my Ray to go in a random direction when i shoot the shotgun and then later on i am going to add multiple bullets per shot and all that. I just wanted to say that ive been searching for a few hours and have not found a topic with the same ray as me. Heres my code for the ray:

Ray ray = new Ray(Camera.main.transform.position,Camera.main.transform.forward);

The problem is, as u can see, im shooting out of the center of my players camera.
so i need some script to work with that. Thanks in advace, ElementalVenom

I have a universal Gun script that i made Right here
it handles full auto, semi auto, shotgun, sounds, sparks, tracer, accuracy, and has a basic ammo system implemented. You can use it if you want to or you can use pieces of the code to make your own
The Script:

public var spreadFactor : float = 0.02;
public var FireRate : float;
public var damage : float = 10.0;
public var range : float = 800.0;
public var Tracer : ParticleSystem;
public var Rounds : int = 1;
public var FireSound : AudioClip;
public var ReloadSound : AudioClip;
public var ImpactPrefab : Transform;

public var shotgunPellets : int = 7;

public var Use : int = 1;

private var RoundShotGun : int = 0;

public var AmmoLeft : int;

public var AmmoPerClip : int;

private var FullAuto : boolean;
private var SemiAuto : boolean;
private var ShotGun  : boolean;

private var delayTime : float = 1;
private var currentDelay : float = 1;

private var Shooting : boolean;

public var Weapon : WeaponType;

public var Style : GUIStyle;

public enum WeaponType{
ShotGun,
SemiAuto,
FullAuto
};
@script RequireComponent(AudioSource)

function Update(){

if(AmmoLeft <= 1){
if(Input.GetButtonDown("Reload")){
Reload();
}
}










switch(Weapon){
case WeaponType.ShotGun:
FullAuto = false;
SemiAuto = false;
ShotGun = true;
break;
case WeaponType.FullAuto:
FullAuto = true;
SemiAuto = false;
ShotGun = false;
break;
case WeaponType.SemiAuto:
FullAuto = false;
SemiAuto = true;
ShotGun = false;
break;
default:
Debug.Log("Unknown Weapon is set");
}




	currentDelay -= Time.deltaTime / delayTime;



if(Input.GetButtonDown("Fire1")){
if(AmmoLeft >= Use){
if(SemiAuto){
FireOneShot();
}
if(ShotGun){
if(RoundShotGun <= 0){
RoundShotGun += shotgunPellets;
AmmoLeft -= Use;
audio.PlayOneShot(FireSound);
}
}
if(FullAuto){
Shooting = true;
}
}
}

if(RoundShotGun >= 0){
FireShotGun ();
}


if(Input.GetButtonUp("Fire1")){
Shooting = false;
}
if(AmmoLeft <= 0){
Shooting = false;
}

if(Shooting){
if(currentDelay <= 0){
FireOneShot();
currentDelay = FireRate;
}
}

}

private var rot = Quaternion.FromToRotation(Vector3.up, hit.normal);
var hit : RaycastHit;

function FireShotGun (){
var direction = transform.TransformDirection(Vector3.forward);
direction.x += Random.Range(-spreadFactor, spreadFactor);
direction.y += Random.Range(-spreadFactor, spreadFactor);
direction.z += Random.Range(-spreadFactor, spreadFactor);
var hit : RaycastHit;
var localOffset = transform.position + (transform.up);
if (Physics.Raycast (localOffset, direction, hit, range)) {
Debug.DrawLine(localOffset, hit.point, Color.green, 2, false);
Instantiate(ImpactPrefab, hit.point, rot);
RoundShotGun -= 1;
// - send damage to object we hit - \\
hit.collider.SendMessageUpwards("Damage", damage, SendMessageOptions.DontRequireReceiver);
}
}

function FireOneShot(){
var direction = transform.TransformDirection(Vector3.forward);
direction.x += Random.Range(-spreadFactor, spreadFactor);
direction.y += Random.Range(-spreadFactor, spreadFactor);
direction.z += Random.Range(-spreadFactor, spreadFactor);
var hit : RaycastHit;
var localOffset = transform.position + (transform.up);
Tracer.Emit(Rounds);
if (Physics.Raycast (localOffset, direction, hit, range)) {
Debug.DrawLine(localOffset, hit.point, Color.cyan, 2, false);
audio.PlayOneShot(FireSound);
Instantiate(ImpactPrefab, hit.point, rot);
AmmoLeft -= Use;
// - send damage to object we hit - \\
hit.collider.SendMessageUpwards("Damage", damage, SendMessageOptions.DontRequireReceiver);
}
}

function OnGUI (){
GUI.Label(Rect(Screen.width/2 + 350,10,45,45), "" + AmmoLeft + "/" + "Infinite", Style);
}
function Reload (){
//if(Scriptforammo.Ammovariable >= AmmoPerClip){
audio.PlayOneShot(ReloadSound);
AmmoLeft += AmmoPerClip;
//}
}

Also A damage receiver for it:

var health = 100;
var HitEffect : Transform;
var KillEffect : Transform;
var PointOfEffects : Transform;

function Damage(damage: int){
    health -= damage;
    var HitEffectShow : Transform = Instantiate(HitEffect, PointOfEffects.position, 
                                               PointOfEffects.rotation);
    }
function Update () 
{
	
	
	if(health <= 0){
		
    var KillEffectShow : Transform = Instantiate(KillEffect, PointOfEffects.position, 
                                               PointOfEffects.rotation);                                         
    Destroy(gameObject);                                           
	}
}

also to effectively use this script you need to setup a reload key

Hope this helps!
-T.D.M.3