Hi, I'm sure there's a simple solution to this problem but as a beginner I'm a bit stumped. I'd like to control the volume of the audio source using the velocity of the gameobject? Any help is much appreciated. /J

using UnityEngine;
using System.Collections;

public class playerSound : MonoBehaviour {

	float speed;
	float volume;
	private AudioSource rain;

	 
	void Start () {


		volume = GetComponent<AudioSource> ().volume = 0f; 
		speed = GetComponent<Rigidbody> ().velocity.magnitude;

	}
	
	// Update is called once per frame
	void Update ()
	{
	

	}


	
}

It looks like the rain audiosource variable isn’t used so you can delete that.
And, depends on how you want the velocity to control the volume.
You can simply set the volume to the velocity

volume = speed;

so when the velocity is 0 the volume is 0 too.

or

volume = speed * 2;

Please give us more details about what you need.

Well it ain’t exactly breaking new barriers but if someone else finds themselves with a similar problem, this is how I solved it.

using UnityEngine;
using System.Collections;

public class changeVol : MonoBehaviour 
{
	public float vol;
	public float speed;


	void Update ()
	{
		//1. vol and speed is assigned to and get the values from the following.
		vol = GetComponent<AudioSource> ().volume;
		speed = GetComponent<Rigidbody> ().velocity.magnitude;

		//3. speed is clamped to fit level parameters, prob not necessary.
		speed = (Mathf.Clamp(speed, 0.0f,1.0f));

		//4.vol is assinged to the audio source level control.
		Volume (vol);
		GetComponent<AudioSource> ().volume = vol;
	}

	//2.vol is sent here to be assigned the speed value (speed of the player).
	void Volume (float newVol)

	{
		
		vol = speed;
	}





}