- Home /
Randomizing sounds (on keypress)?
hey everyone, im working on a game where you can "burp" by pressing the b key in game, i got a little bored with hearing the same sound over and over so i made another sound, and a script that let it have 2 sounds, but from here i have no idea how i could "randomize" the order of these sounds and also how i could add more sounds (below is my script)
var canPlayAudio = true;
var waitTime = 1.0;
var whichBurp : boolean = true;
var Burp1 : AudioClip;
var Burp2 : AudioClip; //Drag your audio clip here in the Inspector.
function Update ()
{
AudioController();
}
function AudioController()
{
if (Input.GetKeyDown ("b") && canPlayAudio && whichBurp)
{
canPlayAudio = false;
audio.PlayOneShot(Burp1);
yield WaitForSeconds(waitTime);
whichBurp = false;
canPlayAudio = true;
}else
if (Input.GetKeyDown ("b") && canPlayAudio && whichBurp == false)
{
canPlayAudio = false;
audio.PlayOneShot(Burp2);
yield WaitForSeconds(waitTime);
whichBurp = true;
canPlayAudio = true;
}
}
Also, on a different topic, how would i make a particle system for what appears to be a stream of "vomit"? Thank you guys alot, atmos :)
Answer by Jeff-Kesselman · Jun 17, 2014 at 10:55 PM
Put your burps in an Array and use Random.Range to select one http://docs.unity3d.com/ScriptReference/Random.Range.html
You already have the answer on your vomit, you need to create a particle system. One that ejects sideways and has a pretty fair gravitational pull down.
You use the http://docs.unity3d.com/Manual/class-ParticleSystem.html inspector to edit your particle system. If you have never done particle system before you might want to start here: https://www.youtube.com/watch?v=xnK5g2z9ESQ
Thanks man, i tried mucking around with particles but it just plain doesnt look good, any more tips? THAN$$anonymous$$S a heap anyways!
Your answer