MicrophoneInput.GetAveragedVolume C# (CSharp) Method

GetAveragedVolume() private method

private GetAveragedVolume ( ) : float
return float
    float GetAveragedVolume()
    {
        float[] data = new float[256];
        float a = 0;
        audio_source.GetOutputData(data, 0);
        foreach (float s in data)
        {
            a += Mathf.Abs(s);
        }
        return a / 256;
    }

Usage Example

コード例 #1
0
    private void Update()
    {
        if (microphone.GetAveragedVolume() > 0.01)
        {
            inputManager.Shoot();
        }


        //if (Input.GetButton("Fire2"))
        //    inputManager.Shoot();
        if (Input.GetKeyDown(KeyCode.R))
        {
            inputManager.RestartGame();
        }
    }