Version: 2021.2
public void Play (ulong delay= 0);

参数

delay 已弃用。以样本数为单位的延时,假设采样率为 44100Hz(意味着 Play(44100) 将使播放延时整整 1 秒)。

描述

播放 clip

The delay parameter is deprecated, please use the newer AudioSource.PlayDelayed function instead which specifies the delay in seconds.

如果 AudioSource.clip 设置为正在播放的同一剪辑, 则该剪辑听起来将像是重新开始播放一样。AudioSource 假设 所有 Play 调用将播放新的音频剪辑。

__注意:__AudioSource.PlayScheduled API 可以让您更准确地控制播放音频剪辑的时间。

using UnityEngine;

// The Audio Source component has an AudioClip option. The audio // played in this example comes from AudioClip and is called audioData.

[RequireComponent(typeof(AudioSource))] public class ExampleScript : MonoBehaviour { AudioSource audioData;

void Start() { audioData = GetComponent<AudioSource>(); audioData.Play(0); Debug.Log("started"); }

void OnGUI() { if (GUI.Button(new Rect(10, 70, 150, 30), "Pause")) { audioData.Pause(); Debug.Log("Pause: " + audioData.time); }

if (GUI.Button(new Rect(10, 170, 150, 30), "Continue")) { audioData.UnPause(); } } }

另请参阅:StopPauseclipPlayScheduled 函数。