mirror of
https://github.com/FriendshipIsEpic/FiE-Game.git
synced 2024-11-23 14:17:59 +01:00
33 lines
706 B
C#
33 lines
706 B
C#
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace Fie.Utility
|
|
{
|
|
[RequireComponent(typeof(AudioSource))]
|
|
public class FieUtilRandomAudioPlayer : MonoBehaviour
|
|
{
|
|
[SerializeField]
|
|
private List<AudioClip> _audioClips = new List<AudioClip>();
|
|
|
|
private Lottery<AudioClip> _lotter = new Lottery<AudioClip>();
|
|
|
|
private AudioSource _audioSource;
|
|
|
|
private void Awake()
|
|
{
|
|
_audioSource = GetComponent<AudioSource>();
|
|
if (_audioClips != null && _audioClips.Count > 0)
|
|
{
|
|
_lotter.InitializeFromListData(_audioClips);
|
|
}
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
if (_lotter.IsExecutable() && !(_audioSource == null))
|
|
{
|
|
_audioSource.PlayOneShot(_lotter.Lot());
|
|
}
|
|
}
|
|
}
|
|
}
|