How to create a rolling sound that only plays when object is moving?

i have finished the roll a ball tutorial and am trying to add a rolling sound effect. I don’t want the sound to play when the ball is moving and it would be great if it could get louder, the faster the ball is moving.

To detect if an object is moving you could compare it to its position during the previous FixedUpdate. Would look something like this:

private Vector3 PreviousPosition;

void FixedUpdate(){
if(PreivousPosition != transform.position)
{
// play sound
}
PreviousPosition = transform.position;
}

Just use this script when trying to do it and it will work
using UnityEngine;

public class ScriptExample : MonoBehaviour
{
void Start()
{
// Sets the position to be somewhere inside a circle
// with radius 5 and the center at zero. Note that
// assigning a Vector2 to a Vector3 is fine - it will
// just set the X and Y values.
transform.position = Random.insideUnitCircle * 5;
}
}

@Jaredrobb1