Trouble getting footstep sounds to play when I walk

Hey everyone,
I’m currently making an FPS game and I have a script but it doesn’t seem to work properly…The sounds play after i walk and then stop walking, and if i start walking again they stop. I’ll show you the script and hope you can help me out.

Thanks :slight_smile:

/**
* Script made by OMA [www.armedunity.com]
**/

var concrete : AudioClip[];
var wood : AudioClip[];
var dirt : AudioClip[];
var metal : AudioClip[];
var sand : AudioClip[];
var grass : AudioClip[];
var snow : AudioClip[];
var water : AudioClip[];
var audioStepLengthCrouch : float = 0.65;
var audioStepLengthWalk : float = 0.45;
var audioStepLengthRun : float = 0.25;
var minWalkSpeed : float = 6.0;
var maxWalkSpeed : float = 10.0;
var audioVolumeCrouch = 0.3;
var audioVolumeWalk = 0.4;
var audioVolumeRun = 1.0;
private var step : boolean = true;


function OnControllerColliderHit (hit : ControllerColliderHit) {
var controller : CharacterController = GetComponent(CharacterController);

if (controller.isGrounded  controller.velocity.magnitude < maxWalkSpeed  controller.velocity.magnitude > minWalkSpeed  hit.gameObject.tag == "Concrete"   step == true || controller.isGrounded  controller.velocity.magnitude < maxWalkSpeed  controller.velocity.magnitude > minWalkSpeed  hit.gameObject.tag == "Untagged"  step == true ) {
		WalkOnConcrete();
	} else if (controller.isGrounded  controller.velocity.magnitude > maxWalkSpeed  hit.gameObject.tag == "Concrete"  step == true || controller.isGrounded  controller.velocity.magnitude > maxWalkSpeed  hit.gameObject.tag == "Untagged"  step == true) {
		RunOnConcrete();
	} else if (controller.isGrounded  controller.velocity.magnitude < minWalkSpeed  controller.velocity.magnitude > 1.0  hit.gameObject.tag == "Concrete"  step == true || controller.isGrounded  controller.velocity.magnitude < minWalkSpeed  controller.velocity.magnitude > 1.0  hit.gameObject.tag == "Untagged"  step == true) {
		CrouchOnConcrete();
	} else if (controller.isGrounded  controller.velocity.magnitude < maxWalkSpeed  controller.velocity.magnitude > minWalkSpeed  hit.gameObject.tag == "Wood"  step == true) {
		WalkOnWood();
	} else if (controller.isGrounded  controller.velocity.magnitude > maxWalkSpeed  hit.gameObject.tag == "Wood"  step == true) {
		RunOnWood();
	} else if (controller.isGrounded  controller.velocity.magnitude < minWalkSpeed  controller.velocity.magnitude > 1.0  hit.gameObject.tag == "Wood"  step == true) {
		CrouchOnWood();
	} else if (controller.isGrounded  controller.velocity.magnitude < maxWalkSpeed  controller.velocity.magnitude > minWalkSpeed  hit.gameObject.tag == "Dirt"  step == true) {
		WalkOnDirt();
	} else if (controller.isGrounded  controller.velocity.magnitude > maxWalkSpeed  hit.gameObject.tag == "Dirt"  step == true) {
		RunOnDirt();
	} else if (controller.isGrounded  controller.velocity.magnitude < minWalkSpeed  controller.velocity.magnitude > 1.0  hit.gameObject.tag == "Dirt"  step == true) {
		CrouchOnDirt();
	} else if (controller.isGrounded  controller.velocity.magnitude < maxWalkSpeed  controller.velocity.magnitude > minWalkSpeed  hit.gameObject.tag == "Metal"  step == true) {
		WalkOnMetal();
	} else if (controller.isGrounded  controller.velocity.magnitude > maxWalkSpeed  hit.gameObject.tag == "Metal"  step == true) {
		RunOnMetal();
	} else if (controller.isGrounded  controller.velocity.magnitude < minWalkSpeed  controller.velocity.magnitude > 1.0  hit.gameObject.tag == "Metal"  step == true) {
		CrouchOnMetal();		
	} else if (controller.isGrounded  controller.velocity.magnitude < maxWalkSpeed  controller.velocity.magnitude > minWalkSpeed  hit.gameObject.tag == "Sand"  step == true) {
		WalkOnSand();
	} else if (controller.isGrounded  controller.velocity.magnitude > maxWalkSpeed  hit.gameObject.tag == "Sand"  step == true) {
		RunOnSand();
	} else if (controller.isGrounded  controller.velocity.magnitude < minWalkSpeed  controller.velocity.magnitude > 1.0  hit.gameObject.tag == "Sand"  step == true) {
		CrouchOnSand();		
	} else if (controller.isGrounded  controller.velocity.magnitude < maxWalkSpeed  controller.velocity.magnitude > minWalkSpeed  hit.gameObject.tag == "Grass"  step == true) {
		WalkOnGrass();
	} else if (controller.isGrounded  controller.velocity.magnitude > maxWalkSpeed  hit.gameObject.tag == "Grass"  step == true) {
		RunOnGrass();
	} else if (controller.isGrounded  controller.velocity.magnitude < minWalkSpeed  controller.velocity.magnitude > 1.0  hit.gameObject.tag == "Grass"  step == true) {
		CrouchOnGrass();		
	} else if (controller.isGrounded  controller.velocity.magnitude < maxWalkSpeed  controller.velocity.magnitude > minWalkSpeed  hit.gameObject.tag == "Snow"  step == true) {
		WalkOnSnow();
	} else if (controller.isGrounded  controller.velocity.magnitude > maxWalkSpeed  hit.gameObject.tag == "Snow"  step == true) {
		RunOnSnow();	
	} else if (controller.isGrounded  controller.velocity.magnitude < minWalkSpeed  controller.velocity.magnitude > 1.0 hit.gameObject.tag == "Snow"  step == true) {
		CrouchOnSnow();		
	} else if (controller.isGrounded  controller.velocity.magnitude < maxWalkSpeed  controller.velocity.magnitude > minWalkSpeed  hit.gameObject.tag == "Water"  step == true) {
		WalkOnWater();
	} else if (controller.isGrounded  controller.velocity.magnitude > maxWalkSpeed  hit.gameObject.tag == "Water"  step == true) {
		RunOnWater();
	} else if (controller.isGrounded  controller.velocity.magnitude < minWalkSpeed  controller.velocity.magnitude > 1.0  hit.gameObject.tag == "Water"  step == true) {
		CrouchOnWater();		
	}	
}

/////////////////////////////////// CONCRETE ////////////////////////////////////////
function CrouchOnConcrete() {
	step = false;
	audio.clip = concrete[Random.Range(0, concrete.length)];
	audio.volume = audioVolumeCrouch;
	audio.Play();
	yield WaitForSeconds (audioStepLengthCrouch);
	step = true;
}

function WalkOnConcrete() {
	step = false;
	audio.clip = concrete[Random.Range(0, concrete.length)];
	audio.volume = audioVolumeWalk;
	audio.Play();
	yield WaitForSeconds (audioStepLengthWalk);
	step = true;
}

function RunOnConcrete() {
	step = false;
	audio.clip = concrete[Random.Range(0, concrete.length)];
	audio.volume = audioVolumeRun;
	audio.Play();
	yield WaitForSeconds (audioStepLengthRun);
	step = true;
}	


////////////////////////////////// WOOD /////////////////////////////////////////////
function CrouchOnWood(){
	step = false;
	audio.clip = wood[Random.Range(0, wood.length)];
	audio.volume = audioVolumeCrouch;
	audio.Play();
	yield WaitForSeconds (audioStepLengthCrouch);
	step = true;
}

function WalkOnWood() {
	step = false;
	audio.clip = wood[Random.Range(0, wood.length)];
	audio.volume = audioVolumeWalk;
	audio.Play();
	yield WaitForSeconds (audioStepLengthWalk);
	step = true;
}

function RunOnWood() {
	step = false;
	audio.clip = wood[Random.Range(0, wood.length)];
	audio.volume = audioVolumeRun;
	audio.Play();
	yield WaitForSeconds (audioStepLengthRun);
	step = true;
}

/////////////////////////////////// DIRT //////////////////////////////////////////////
function CrouchOnDirt(){
	step = false;
	audio.clip = dirt[Random.Range(0, dirt.length)];
	audio.volume = audioVolumeCrouch;
	audio.Play();
	yield WaitForSeconds (audioStepLengthCrouch);
	step = true;
}

function WalkOnDirt() {
	step = false;
	audio.clip = dirt[Random.Range(0, dirt.length)];
	audio.volume = audioVolumeWalk;
	audio.Play();
	yield WaitForSeconds (audioStepLengthWalk);
	step = true;
}

function RunOnDirt() {
	step = false;
	audio.clip = dirt[Random.Range(0, dirt.length)];
	audio.volume = audioVolumeRun;
	audio.Play();
	yield WaitForSeconds (audioStepLengthRun);
	step = true;
}


////////////////////////////////// METAL ///////////////////////////////////////////////
function CrouchOnMetal(){
	step = false;
	audio.clip = metal[Random.Range(0, metal.length)];
	audio.volume = audioVolumeCrouch;
	audio.Play();
	yield WaitForSeconds (audioStepLengthCrouch);
	step = true;
}

function WalkOnMetal() {	
	step = false;
	audio.clip = metal[Random.Range(0, metal.length)];
	audio.volume = audioVolumeWalk;
	audio.Play();
	yield WaitForSeconds (audioStepLengthWalk);
	step = true;
}

function RunOnMetal() {
	step = false;
	audio.clip = metal[Random.Range(0, metal.length)];
	audio.volume = audioVolumeRun;
	audio.Play();
	yield WaitForSeconds (audioStepLengthRun);
	step = true;
}


////////////////////////////////// SAND ///////////////////////////////////////////////
function CrouchOnSand(){
	step = false;
	audio.clip = sand[Random.Range(0, sand.length)];
	audio.volume = audioVolumeCrouch;
	audio.Play();
	yield WaitForSeconds (audioStepLengthCrouch);
	step = true;
}

function WalkOnSand() {	
	step = false;
	audio.clip = sand[Random.Range(0, sand.length)];
	audio.volume = audioVolumeWalk;
	audio.Play();
	yield WaitForSeconds (audioStepLengthWalk);
	step = true;
}

function RunOnSand() {
	step = false;
	audio.clip = sand[Random.Range(0, sand.length)];
	audio.volume = audioVolumeRun;
	audio.Play();
	yield WaitForSeconds (audioStepLengthRun);
	step = true;
}

////////////////////////////////// GRASS ///////////////////////////////////////////////
function CrouchOnGrass(){
	step = false;
	audio.clip = grass[Random.Range(0, grass.length)];
	audio.volume = audioVolumeCrouch;
	audio.Play();
	yield WaitForSeconds (audioStepLengthCrouch);
	step = true;
}

function WalkOnGrass() {	
	step = false;
	audio.clip = grass[Random.Range(0, grass.length)];
	audio.volume = audioVolumeWalk;
	audio.Play();
	yield WaitForSeconds (audioStepLengthWalk);
	step = true;
}

function RunOnGrass() {
	step = false;
	audio.clip = grass[Random.Range(0, grass.length)];
	audio.volume = audioVolumeRun;
	audio.Play();
	yield WaitForSeconds (audioStepLengthRun);
	step = true;
}

////////////////////////////////// SNOW ///////////////////////////////////////////////
function CrouchOnSnow(){
	step = false;
	audio.clip = snow[Random.Range(0, snow.length)];
	audio.volume = audioVolumeCrouch;
	audio.Play();
	yield WaitForSeconds (audioStepLengthCrouch);
	step = true;
}

function WalkOnSnow() {	
	step = false;
	audio.clip = snow[Random.Range(0, snow.length)];
	audio.volume = audioVolumeWalk;
	audio.Play();
	yield WaitForSeconds (audioStepLengthWalk);
	step = true;
}

function RunOnSnow() {
	step = false;
	audio.clip = snow[Random.Range(0, snow.length)];
	audio.volume = audioVolumeRun;
	audio.Play();
	yield WaitForSeconds (audioStepLengthRun);
	step = true;
}

////////////////////////////////// SNOW ///////////////////////////////////////////////
function CrouchOnWater(){
	step = false;
	audio.clip = water[Random.Range(0, water.length)];
	audio.volume = audioVolumeCrouch;
	audio.Play();
	yield WaitForSeconds (audioStepLengthCrouch);
	step = true;
}

function WalkOnWater() {	
	step = false;
	audio.clip = water[Random.Range(0, water.length)];
	audio.volume = audioVolumeWalk;
	audio.Play();
	yield WaitForSeconds (audioStepLengthWalk);
	step = true;
}

function RunOnWater() {
	step = false;
	audio.clip = water[Random.Range(0, water.length)];
	audio.volume = audioVolumeRun;
	audio.Play();
	yield WaitForSeconds (audioStepLengthRun);
	step = true;
}

@script RequireComponent(AudioSource)

The result is exactly the same as before, the audio plays when i stop walking and not when I walk :frowning:

Here you can see script in action…

Ok, well I applied the script to my First Person Controller, and selected the footstep sounds, I added an Audio Source and played it. Am I doing anything wrong?

what else you have added on your root collider of CC???
which script are you use to move?

I’m just using the basic script included in the First Person Controller prefab, I haven’t changed anything in any of the scripts.

Ok, i will send you PM and you will find solution!