Updating the intensity with audio

Hey guys,

I have a ambient wind zone with a certain intensity that I want to change depending on level of the audio input. For example: if there is no incoming sound from the microphone (intensity = 5), if there is incoming sound (intensity = 5+). I watched a youtube tutorial that showed me how to use the microhpone to move a cube up and down.

using UnityEngine;
using System.Collections;

public class SoundMovement : MonoBehaviour
{

    public float sensitivity = 100;
    public float loudness = 0;
    AudioSource _audio;

    public object windzone;

    // Use this for initialization

    void Start()
    {
        _audio = GetComponent<AudioSource>();
        _audio.clip = Microphone.Start(null, true, 10, 44100);
        _audio.loop = true;
        _audio.mute = true;
        while (!(Microphone.GetPosition(null) > 0)) { }
        _audio.Play();
    }

    // Update is called Once per Frame

    void Update()
    {
        loudness = GetAveragedVolume() * sensitivity;
        if (loudness > 8)
            this.GetComponent<Rigidbody>().velocity = new Vector2(this.GetComponent<Rigidbody>().velocity.x, 4);
    }
    //
    float GetAveragedVolume()
    {
        float[] data = new float[256];
        float a = 0;
        _audio.GetOutputData(data, 0);
        foreach (float s in data)
        {
            a += Mathf.Abs(s);
        }
        return a / 256;
    }
}

This code works fine but I recognize this line that needs to change:

this.GetComponent<Rigidbody>().velocity = new Vector2(this.GetComponent<Rigidbody>

Does anyone have any idea on how to instead of accesing the rigidbody of the object, acces the intensity of the ambient wind zone? I’m fairly new to programming

Kind regards

hey any update regarding your query I’m something similar so can you help me out