Question about Gun Sounds

I’m using a Rigid Body shooting script that I got from a tutorial, and it’s working for what I’m making (A Multiplayer Scifi FPS), but I want to add a gun sound for when you shoot the gun.

Here;s the original script:

var projectile : Rigidbody;
var speed = 150;

function Update () {

if ( Input.GetButton ("Fire1")) {

clone = Instantiate(projectile, transform.position, transform.rotation);
clone.velocity = transform.TransformDirection( Vector3 (0, 0, speed));

Destroy (clone.gameObject, 5);

}}

And here’s how I added the one part (keep in mind, I’m a giant noob when it comes to scripting)

var projectile : Rigidbody;
var speed = 10;
var sound : AudioClip;

function Update () {

if ( Input.GetButton ("Fire1")) {

clone = Instantiate(projectile, transform.position, transform.rotation);
clone.velocity = transform.TransformDirection( Vector3 (0, 0, speed));

Destroy (clone.gameObject, 5);

}}


 
function Start(){
    audio.clip = sound;
}
 
function Update (){    
    if(Input.GetButtonDown(0)){
        audio.Play();
    }
}

When I try to use it, I can’t even shoot the gun :confused:
Please help!

1.) you are using the Update() function twice.
2.) You are using the same if statement - just worded differently.

Try using this:

var projectile : Rigidbody;
var speed = 10;
var sound : AudioClip;
 
function Update () {
 
if ( Input.GetButton ("Fire1")) {
 
clone = Instantiate(projectile, transform.position, transform.rotation);
clone.velocity = transform.TransformDirection( Vector3 (0, 0, speed));

audio.Play();
Destroy (clone.gameObject, 5);

   }
}
 
function Start(){
    audio.clip = sound;
}