Skip to content

Instantly share code, notes, and snippets.

@yunojy
Created December 24, 2016 15:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yunojy/f2e87055ab5ca2ae280d0c3410ba7e13 to your computer and use it in GitHub Desktop.
Save yunojy/f2e87055ab5ca2ae280d0c3410ba7e13 to your computer and use it in GitHub Desktop.
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