How do I play the appropriate sound when Bouncing and Rolling?

Hello, I am a little stuck. I’m new to Unity, and I am wondering about Collisions. How can I detect a collision between and another object (like the ground/Plane)?

I am making a test ball game. I have setup a Camera Controller and Player Controller and setup lighting and added some 3d models from SketchUp. And when the ball rolls, I want to play a rolling sound. And when the ball falls off the edge onto another object, I want it to play a single bounce sound when it ‘hits’ the other object and once it’s finished bouncing and I begin to roll the ball again, I want to keep playing the rolling sound.

I’m a little unsure of how I can stop playing the rolling sound though when it’s just staying still.

I know how to play sounds too. I just don’t know how to play sounds when it hits an object and when it’s rolling.

Any help will be much appreciated.

For the bounce/rolling audio, you could do something as simple as making a variable “Grounded” that when the OnCollisionEnter() function is called grounded equals true, and when the OnCollisionExit() function is called, it equals false. So when the ball’s Grounded equals true, you play the rolling audio, and when the OnCollisionEnter() function is called, you play the bounce audio.

to check if the ball is idle, you could use a line of code like:

if (GetComponent.<Rigidbody>().velocity.magnitude < 0.01 ){
//The Ball is not rolling
}else{
//The Ball is rolling
}

You could add a simple variable like “Rolling” and then use it to control whether or not the rolling audio is played. Hope this helped!