使用AudioListener.GetSpectrumData
获取用于调制粒子系统中最大粒子的音频谱。我使用这个精确的方法与我的草图的其他部分来调制照明的强度,立方体,球体和文本的大小...)但这不适用于粒子系统。有什么想法吗?
using UnityEngine;
public class Max_Particles_Blow_Spectrum : MonoBehaviour {
[Range(1.0f, 30000.0f)]
public float phi = 0.0f;
private ParticleSystem ps;
void Start()
{
ps = GetComponent<ParticleSystem>();
}
void Update()
{
float[] phi = AudioListener.GetSpectrumData(1024, 0, FFTWindow.Hamming);
var main = ps.main;
float amplitude = Mathf.RoundToInt(phi[1]) ;
// i thought it was an issue with the float array to I tried converting it to an int
main.maxParticles = Mathf.RoundToInt(amplitude);
}
void OnGUI()
{
phi = GUI.HorizontalSlider(new Rect(25, 25, 100, 30), phi, 1f, 30000.0f);
}
}