Created
May 13, 2015 18:54
-
-
Save radiatoryang/4433397facc83a315acf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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