- Home /
Audio Clip Plays as volume 1 multiple times. But I told it not to... Bad Audio. bad.
Hello Unity Community,
Here is the deal, I have a bunch of sounds, Jump, grab, shoot, land, background music. All works fine. Then I have a sound that needs to happen if the character travels at a certain speed.
It should play the audio once, at volume 0.1 but ofcouse it plays it multiple times because it travels at that speed for more than 1 run of the code. So I aded a roadblock, that if it travels at that speed ones, if it plays the sound ones, it switches a boolean to false and then a function that runs a countdown to turn the boolean back to true. It should only play the sound if the boolean is true. But it appears to be executed more than ones, because sometimes it will play the audio ones at the correct volume, and sometimes it seems to either play the sound multiple times and thats why its getting louder or its playing the sound at a volume of 1 instead of 0.1. Here are code snips of the problem. Thank you for your time.
var WohooSound : AudioClip; private var playingwoo : boolean; static var SoundOff : boolean;
function Awake(){ SoundOff = false; playingwoo= false;
}
function FixedUpdate(){ var PlayerSpeed = rigidbody.velocity.magnitude;
if(PlayerSpeed > 20 && !playingwoo){ PlayWooSound(); return; } }
function PlayWooSound(){ if(!playingwoo && !SoundOff){ if(!audio.isPlaying){ playingwoo = true; audio.Stop(); audio.volume = 0.1; audio.PlayOneShot(WohooSound); ResetWooSound(); return; } } } function ResetWooSound(){ yield WaitForSeconds(4); playingwoo = false; return; }
I am Experiencing the same problem when he gets hit.
var ScreemSound : AudioClip; private var dead : boolean;
function Awake(){ dead = false;
} function OnTriggerEnter(other : Collider) {
if (other.gameObject.CompareTag("firecomet")){ die(); audio.Stop(); audio.volume = 0.1; audio.PlayOneShot(ScreemSound); return;
} }
function die(){
dead = true;
}
Answer by Anxo · Sep 21, 2010 at 04:35 PM
Looks like I found the problem, but not sure why it is happening. I have Object "A" and "B" with audio sources on it. Object "A" has a clip that needs to play at a volume of 0.1, Object "B" has a clip that needs to play at a volume of 1. if Object "A"'s clip is playing and Object "B"'s clip is triggered with audio.volume = 1;, it will not only change the volume to 1 for object B but also for A.
Your answer
Follow this Question
Related Questions
Inconsistent ReverbZone / AudioSource.volume behavior 2 Answers
Breathing volume increases as player gets more tired 0 Answers
Android: Ringer Volume Control 0 Answers
what audio.volume level on iphone would match the music player volume? 1 Answer
Fading out before load script not functioning correctly? 2 Answers