I’m working on integrating audio to my game. I’m playing sound by attaching sound to camera’s audio source.
But, I need to randomize the audio source of my camera. can some one please help me with this ?
how should I manipulate this ?
I’m currently using this:
public class PlayRandomAudio : MonoBehaviour {
public Camera MainCamera;
public AudioClip[] sounds; // set the array size and fill the elements with the sounds
void PlayRandom ()
{ // call this function to play a random sound
AudioSource.Instantiate(MainCamera);
if (audio.isPlaying) return; // don't play a new sound while the last hasn't finished
audio.clip = sounds[(int)Random.Range(0.0f,4.0f)];
MainCamera.audio.Play();
}
}