- Home /
Duplicate Question
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 :D ) 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
Answer by Jeejo · May 12, 2013 at 12:21 PM
This should work:
var handGunShot : AudioClip;
function Update () {
if(Input.GetMouseButtonDown(0)) {
audio.PlayOneShot(handGunShot);
}
}
Should i change the handGunShot to what my mp3 file name is?
Also, you shouldn't put the sound directly into the AudioSource. When you play the game the script will work it out by itself. (NOTE: This is just in case, I'm not sure if you have been doing this, but I just wanted to post it in case you weren't.)
Can you give me more information on what to do cause now im not so sure anymore...
Thanks.
No, you don't have to. You just drag the audio clip into the inspector (under the script, next to Hand Gun Shot).
$$anonymous$$y sound isn't called handGunShot but $$anonymous$$P5$$anonymous$$ so i have a gun called Gun Prefab should i drag the script with sound into the gun and then it should work? If so please say because i really need help.
Answer by Sanky · May 12, 2013 at 12:12 PM
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.
Can you help me a little bit more? I Did the javascript made it and put the sound in. Now i put the script inside my gun model and it still plays on start of game and doesn't when i click in screen. :/
Thanks
Vince
have you removed 3d sound option from that sound clip and also you have to attach audio source component to your gun object then add that clip to their then the clip will plays well.
also LOO$$anonymous$$ at the inspector, and TURN OFF automatic play. that's what is making it play on load.
Answer by malekbakeer · May 12, 2013 at 12:56 PM
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
Hi,
so, i'm working on a game, and i have a dialog between two people. I already make, that when the player click on button next, the next dialoge is shown. i have 9 dialogs, so the player must press 9 times on button next, to end up dialoge.
The problem i have now, that i want when text is shown the audio clip(i recorded voices and export as mp3 in audacity) is on volume too. i have 9 audio clips and i can't pair it with texts.
any solutions?
Thanks
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Audio on Collision code doesn't work? 2 Answers
Change Music When GameObject is Grabbed? 1 Answer
I need help scripting a melee attack 0 Answers