Instantly share code, notes, and snippets.

Embed
What would you like to do?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(AudioSource))]
public class PlayAudio : MonoBehaviour {
public AudioClip[] audioClips;
private AudioSource audioSource;
void Start() {
audioSource = gameObject.GetComponent<AudioSource>();
}
public void RandomPlay() {
audioSource.clip = audioClips[Random.Range(0, audioClips.Length)];
audioSource.Play();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment