- 首先给目标物体添加Audio Source组件
- 新建Script脚本,代码如下
using Spine.Unity;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class yateland : MonoBehaviour
{
public AudioClip[] audios;
// Start is called before the first frame update
void Start()
{
StartCoroutine(Audio());
}
// Update is called once per frame
void Update()
{
}
IEnumerator Audio()
{
for (int i = 0; i < audios.Length; i++)
{
this.GetComponent<AudioSource>().clip = audios[i];
this.GetComponent<AudioSource>().Play();
yield return new WaitForSeconds(audios[i].length);
}
}
}
- 将脚本挂给物体
- 输入播放音乐段数

- 拖拽音乐到下方
本文介绍了如何在Unity中实现多段音频的顺序播放。首先,在目标游戏对象上添加Audio Source组件。接着,创建一个Script脚本,包含播放音频段的逻辑。将脚本挂载到物体上,并设置播放音乐的段数。最后,通过拖放操作将各段音乐添加到脚本对应的字段中。
1284

被折叠的 条评论
为什么被折叠?



