AudioSource.timeSamples 时间取样

var timeSamples : int

Description描述

Playback position in PCM samples.

在PCM取样的播放位置。

Use this to read current playback time or to seek to a new playback time in samples, if you want more precise timing than what time variable allows.

使用这个读取当前播放时间或定位一个新的播放时间取样,如果你想比time变量允许更精确的计时。

参见: time变量

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
	void Update() {
		if (Input.GetKeyDown(KeyCode.Return)) {
			audio.Stop();
			audio.Play();
		}
		Debug.Log(audio.timeSamples);
	}
}
// Prints the elapsed time in samples the audio
// source has been playing.
// Press "Return" to start the song and see how the
// time sample gets restarted..
//以秒为单位,打印音频源已经播放所用的取样时间。
//按Return键,开始播放,看看如何获取重新启动的时间
function Update() {
	if(Input.GetKeyDown(KeyCode.Return)) {
		audio.Stop();
		audio.Play();
	}
	Debug.Log(audio.timeSamples);
}
Page last updated: 2011-4-5