Need help with playing audio on click.

Hey guys just a simple question here, i’ve made a gun and i want it to shoot when i press Fire1 ( Yes i know its fire1 :smiley: ) so the script would be something like this?

var handGunShot : SoundClip;

 

function Update(){

if (Input.GetButton("Fire1"){

//shoot the bullet

audio.PlayOneShot(handGunShot);

}

}

I Can change the handgunshot to my audio file right?

Thanks.

  • Vince

var soundPlay : AudioClip;

function Update()
{
if(Input.GetMouseButtonDown(0))
{
audio.Play();
}
}

Abouve script just attach your object and turn of play on awake Boolean from audioSource.

just copy and paste this

var _sound : AudioClip;
         
function Update(){
         
    if (Input.GetButton("Fire1"){
         
        audio.Play("put your sound name here");         
    }

then put the script in your character then chose your soundclip that u wanna play

This should work:

var handGunShot : AudioClip;

function Update () {
     if(Input.GetMouseButtonDown(0)) {
          audio.PlayOneShot(handGunShot);
     }
}