Skip to content

Instantly share code, notes, and snippets.

@radiatoryang
Created May 13, 2015 18:54
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save radiatoryang/4433397facc83a315acf to your computer and use it in GitHub Desktop.
Save radiatoryang/4433397facc83a315acf to your computer and use it in GitHub Desktop.
using UnityEngine;
using System.Collections;
// place on a GameObject with an AudioSource component
[RequireComponent(typeof(AudioSource))]
public class PlayRandomSound : MonoBehaviour {
public AudioClip[] sounds; // assign in inspector
// Use this for initialization
void Start () {
AudioSource audioSource = GetComponent<AudioSource>();
audioSource.clip = sounds[Random.Range (0, sounds.Length)];
audioSource.Play ();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment