Version: 2017.1
public void PlayScheduled (double time);

파라미터

time Time in seconds on the absolute time-line that AudioSettings.dspTime refers to for when the sound should start playing.

설명

Plays the clip at a specific time on the absolute time-line that AudioSettings.dspTime reads from.

This is the preferred way to stitch AudioClips in music players because it is independent of the frame rate and gives the audio system enough time to prepare the playback of the sound to fetch it from media where the opening and buffering takes a lot of time (streams) without causing sudden CPU spikes.

using UnityEngine;
using System.Collections;

[RequireComponent(typeof(AudioSource))] public class ExampleClass : MonoBehaviour { public float bpm = 140.0F; public int numBeatsPerSegment = 16; public AudioClip[] clips = new AudioClip[2]; private double nextEventTime; private int flip = 0; private AudioSource[] audioSources = new AudioSource[2]; private bool running = false; void Start() { int i = 0; while (i < 2) { GameObject child = new GameObject("Player"); child.transform.parent = gameObject.transform; audioSources[i] = child.AddComponent<AudioSource>(); i++; } nextEventTime = AudioSettings.dspTime + 2.0F; running = true; } void Update() { if (!running) return; double time = AudioSettings.dspTime; if (time + 1.0F > nextEventTime) { audioSources[flip].clip = clips[flip]; audioSources[flip].PlayScheduled(nextEventTime); Debug.Log("Scheduled source " + flip + " to start at time " + nextEventTime); nextEventTime += 60.0F / bpm * numBeatsPerSegment; flip = 1 - flip; } } }

The example at AudioSource.SetScheduledEndTime shows how you can play two audio clips without pops or clicks between the clips. The approach is to have two AudioSources with clips attached, and queue up each clip using its AudioSource.

See Also: SetScheduledStartTime.