machine gun sound

I have made a mech type robot for my scene. the top half is what i called the turret.
the turret spind and has an audio source that works fine. inside the turret i have two arms that are combined into one object that also move up and down these also have an audio file attached that works fine. inside the arms i have a prefab to make it shoot, this also works fine. What i want to do is add an audio file to make a firing sound for the guns. I want ot make the sound play when i press the shoot command. Can anybody help me out on how to do this.
i will post the firing script

var projectile : Rigidbody;

var speed = 20;

function Update () {

if ( Input.GetButton (“Fire1”)) {

clone = Instantiate(projectile, transform.position, transform.rotation);

clone.velocity = transform.TransformDirection( Vector3 (0, 0, speed));

Destroy (clone.gameObject, 2);

}}

thanks

wayne

1 Answer

1

You’ll need the sound itself. I think the best result will be a short shot sound with perhaps 3-8 shots in. This should be edited in a sound program to be 100% loopable.

Then you add an Audio Component to your GameObject and drag the wav/ogg file onto your object in the Audio Component inspector.

Lastly, you can access it from script with:

audio.Play();