- Home /
turret rotation audio problem
I made a model of a mech type robot. The problem i have is i want to add a sound file when i rotate it. The keys for rotation are a = right and d =left. i have tried following the posts to assign a audio file to this action but having problems. I add an audio source to the object and then a script to it but it keep getting error problems. Can someone help me out with this? I have tried some scripts i found on the forum but they dont work for me. This is a play on push key action
thanks
wayne
Answer by aldonaletto · Sep 17, 2011 at 07:05 AM
You must add an AudioSource to the object, assign the sound you want to play to the clip property (at the Inspector) and observe the controls: while they are pressed, play the sound - but you must wait the sound end before play it again, or you will get a horrible noise instead:
function Update(){ // check if a OR d pressed
if (Input.GetButton("a") || Input.GetButton("d")){
if (!audio.isPlaying){ // if sound ended...
audio.Play(); // repeat the sound
}
}
}
Your answer
Follow this Question
Related Questions
Audio Play/Stop Trouble 1 Answer
AudioClip doesn't play sound 1 Answer
Change Pitch on Collision 1 Answer
How to play same game music through different levels. 2 Answers