How to play sound when object stops moving?

I’m trying to make a sound play when a vehicle stops moving. Please help me.

First of all, you need to know when your object stops. In order to get to that point, there are two solutions:

  1. If you are using Unity physics, you can check rigidbody.velocity to see if it is a zero vector, and play a sound at that time.
  2. If you are moving your object with updating transform values, then you can check this answer to see a possible solution: How to check if an object has stopped moving? - Questions & Answers - Unity Discussions

Finally, you can keep a flag to check to make sure when to play sound like this:

// your code to understand if object stopped, then set the flag (bool isObjectStopped) to true
if(isObjectStopped && !isMusicPlayed) {
    // play sound here
    isMusicPlayed = true;
// when your object starts to move again, set the flag (bool isObjectStopped) to false