I have this mic input script I’m using for a game of mine that I learned online from http://www.kaappine.fi/tutorials/using-microphone-input-in-unity3d/ it’s pretty straight forward and I’ll post the code below, now this script was working wonderfully and I’ve built a whole game around it using it as the main backbone if you will, after I updated unity to fix the OnApplicationPause() problem I was having the loudness variable now suddenly stays at zero. I use the loudness variable to compare to a threshold to spawn my objects, so you see my problem. The OnApplicationPause now works though *frustrated face. PLEASE HELP
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(AudioSource))]
public class MicrophoneInput : MonoBehaviour {
public float sensitivity = 100f;
public float loudness = 0f;
// Use this for initialization
void Start () {
GetComponent<AudioSource>().clip = Microphone.Start (null, true, 10, 44100);
GetComponent<AudioSource>().loop = true;
GetComponent<AudioSource>().mute = true;
while (!(Microphone.GetPosition(null) > 0)){}
GetComponent<AudioSource>().Play ();
}
// Update is called once per frame
void Update () {
loudness = GetAveragedVolume () * sensitivity;
}
float GetAveragedVolume(){
float[] data = new float[256];
float a = 0f;
GetComponent<AudioSource>().GetOutputData (data, 0);
foreach(float s in data)
{
a += Mathf.Abs(s);
}
return a/256;
}
}