54 lines
1.2 KiB
C#
54 lines
1.2 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace Beyond
|
|
{
|
|
|
|
[RequireComponent(typeof(AudioSource))]
|
|
public class SoundListPlayer : MonoBehaviour
|
|
{
|
|
|
|
public AudioClip[] clips;
|
|
int currentIdx = -1;
|
|
// Use this for initialization
|
|
AudioSource aSource;
|
|
void Start()
|
|
{
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
if (currentIdx < 0)
|
|
return;
|
|
if (aSource.isPlaying == false)
|
|
{
|
|
currentIdx++;
|
|
if (currentIdx < clips.Length)
|
|
{
|
|
aSource.clip = clips[currentIdx];
|
|
if (aSource.clip != null)
|
|
aSource.Play();
|
|
}
|
|
else
|
|
{
|
|
this.enabled = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
public void Play()
|
|
{
|
|
if (clips.Length == 0)
|
|
{
|
|
enabled = false;
|
|
}
|
|
aSource = GetComponent<AudioSource>();
|
|
|
|
currentIdx = 0;
|
|
aSource.clip = clips[currentIdx];
|
|
aSource.Play();
|
|
}
|
|
}
|
|
} |