Skip to content

Instantly share code, notes, and snippets.

@yunojy yunojy/PlayAudio.cs
Created Dec 24, 2016

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
You can’t perform that action at this time.