public AudioClip[] Songs;
// Start is called before the first frame update
void Start()
{
if(Songs == null || Songs.Length == 0)
{
Debug.LogError("请在检查器里指定资源");
}
}
// Update is called once per frame
void Update()
{
if (Input.GetMouseButtonDown(0))
{
NextSong();
}
}
void NextSong()
{
int index = Random.Range(0,Songs.Length);
AudioSource audio = GetComponent<AudioSource>();
audio.clip = Songs[index];
audio.Play();
Debug.Log("播放音乐:" + audio.clip.name);
}
Unity音乐盒
最新推荐文章于 2025-04-23 23:54:24 发布