- Home /
Question by
mavv · Jun 24, 2015 at 10:26 AM ·
audioaudiosourcecomponentspitch
Creating Audio Source for different pitch
Hi. First i tried to using audio.playOneShot(x[i]); to play sounds, but modyfing pitch affect all sounds (even this already playing). So i wrote this:
var a=transform.gameObject.AddComponent.<AudioSource>();
a.volume=volume;
a.clip=sound;
a.pitch=Random.Range(0.8,1.2);
a.Play();
Also i need now delete once used component (because leaving them extremely slows game) , so in Update function i wrote this:
var au=transform.gameObject.GetComponents.<AudioSource>();
for (var u=0;u<au.length;u++){
if (!au[u].isPlaying) Destroy(au[u]);
}
It's working well, but i wondering is there a better, simplier (and efficient) way? I think this also slows game a little. Sorry for my English, I tried to do my best :D
Comment
Your answer
Follow this Question
Related Questions
Pitch changes when i get closer to object with audio source 1 Answer
Weird audio problem 1 Answer
Animate Audio Source Pitch/Speed in Timeline 0 Answers
Gear sound changes smoothed! 0 Answers