public Text data;
string url = "http://localhost/AudioVisualizer/Spiderman.wav";
float[] samples = new float[1024];
public AudioSource source;
public GameObject L,R;
WWW www;
IEnumerator Start()
{
www = new WWW(url);
yield return www;
source = GetComponent<AudioSource>();
source.clip = www.GetAudioClip();
}
void Update()
{
source.GetOutputData(samples, 1);
data.text = samples[0].ToString();
L.transform.localScale = new Vector3(1,Mathf.Abs(samples[0]*2), 1);
R.transform.localScale = new Vector3(1, Mathf.Abs(samples[1]*2), 1);
if (!source.isPlaying)
source.Play();
}
当我在编辑器中运行上面的代码时,它运行得很好。但是当我进行WebGL构建时,没有输出数据。
data.text = samples[0].ToString();
此行给出0作为输出。