- Home /
Get acess and switch to many audio source in a single Object HELP!!
supose that i have 3 diferents audiosources in a cube... if i want to make them play individualy in a specific moment...exemple
if the cube jump i want the audiosource named jump play
if it crouching i want the audiosource named crouch play
if it got hit i want the audiosource gothit play!!...how do i do that...do i have to assign them and how give me all the possibilities if ther are less then 10 LOL!!
Answer by aldonaletto · Nov 08, 2012 at 04:12 AM
You don't need multiple AudioSources - simply use a single AudioSource and play different clips with PlayOneShot:
var jumpSound: AudioClip; // assign sounds to
var crouchSound: AudioClip; // these fields in
var hitSound: AudioClip; // the Inspector
// when the cube jumps:
audio.PlayOneShot(jumpSound);
// when the cube get hit:
audio.PlayOneShot(hitSound);
// and so on
OH!! ok so if i understand i drag the sound in the inspector!! NIC$$anonymous$$..if im right of course?
Yes, that's the idea: drag the sounds to the variables in the Inspector and play the desired one with PlayOneShot.