Slope sliding sound effect

I want a skidding sound effect to play when character controller is sliding down a slope.

Is it a bad approach to add a second collider (trigger) onto the slope just slightly poking out along the edge of the slope to trigger the sound?

2 Answers

2

That approach is good try it out and reply if it works please.

I posted the code for you, feel free to use it

Wasn’t sure if it is the best approach but seems to be working okay.

Add a trigger box collider onto an empty child on your slope then add this script:

var audioVolume = 0.6;

function Awake () {
	audio.volume = audioVolume;
}

function OnTriggerStay (other : Collider) {
	// Check for player
	if (other.CompareTag("Player")) {
		if (!audio.isPlaying)
			audio.Play();
	}
}

function OnTriggerExit () {
	audio.Stop();
}

function Reset() {
	rigidbody.isKinematic = true;
}

@script RequireComponent (AudioSource, Rigidbody)