How can i read the vu meter value from the master audio mixer with c# script ?
You could use the OnAudioFilterRead() method. data[ ] will contain the amplitude values of each sample in a block.
You can insert OnAudioFilterRead()/MonoBehaviours into the audio mixer?
My bad, I thought @Frogger007 was just trying to access an AudioSource VU values. Hmm. Interesting question then. Anyone know how it can be done?
using UnityEngine;
using System.Collections;
public class AudioVolumeOutput : MonoBehaviour
{
public float maxVolume = 1.0f;
public Material sphereMaterial;
private float newdata;
void Start()
{
sphereMaterial = gameObject.GetComponent ().material;
}
void Update()
{
sphereMaterial.color = new Color(newdata, newdata, newdata); // Using the volume values to change the color
sphereMaterial.SetColor (“_EmissionColor”, new Color(newdata, newdata, newdata)); // and the emission of an material
}
void OnAudioFilterRead(float[ ] data, int channels)
{
for (int i = 0; i < data.Length; ++i)
{
data = data * maxVolume;
newdata = data*;*
}
}
}
The script reads the uv volume values and then i use this values to change the color and the emisison values of an material.
Hi Frogger
where are you calling OnAudioFilterRead ?