- Home /
Audio is not playing but i don't have any compiler errors?
Will not play, although the audio source does show the clip as being played, i don't hear it.
#pragma strict
var concreteSound1 : AudioClip [];
var MetalSound1 : AudioClip [];
private var isWalking : boolean = true;
var footstepTime : float = 0.2;
private var isMoving : boolean = false;
private var isJumping : boolean = false;
private var isOnConcrete : boolean = false;
var clipType : String = "";
function Update() {
if (Input.GetAxis("Horizontal")) {
isMoving = true;
} else if (Input.GetAxis("Vertical")) {
isMoving = true;
} else if (Input.GetButtonDown("Jump")) {
isMoving = true;
isJumping = true;
} else if (!Input.GetButton("Jump")) {
isMoving = false;
isJumping = false;
}
//In order for jump to work, there must be a delay in the time from jump button press to actual jump in order for it to register. Also, ensure GetButtonDown on the player jump script, otherwise, it wont work right.
else if (!Input.GetAxis("Horizontal")) {
isMoving = false;
} else if (!Input.GetAxis("Vertical")) {
isMoving = false;
}
}
function OnControllerColliderHit (hit : ControllerColliderHit) {
if (hit.gameObject.tag == "Concrete" && isWalking && isMoving || isJumping && isWalking && isOnConcrete) {
Debug.Log ("Walking On Concrete");
isOnConcrete = true;
WalkOnConcrete();
} else if (hit.gameObject.tag == "Metal" && isWalking && isMoving || isJumping && isWalking) {
Debug.Log ("Walking On Metal");
isOnConcrete = false;
WalkOnMetal();
}
}
function WalkOnConcrete() {
var concreteToPlay : GameObject = GameObject.FindWithTag ("Concrete");
isWalking = false;
yield WaitForSeconds (footstepTime);
audio.clip = concreteSound1 [ Random.Range(0, concreteSound1.Length) ];
clipType = "concreteSound1";
isWalking = true;
}
function WalkOnMetal() {
var MetalToPlay : GameObject = GameObject.FindWithTag ("Metal");
isWalking = false;
yield WaitForSeconds (footstepTime);
audio.clip = MetalSound1 [ Random.Range(0, MetalSound1.Length) ];
clipType = "MetalSound1";
isWalking = true;
}
Comment
Answer by JChilton · Mar 27, 2013 at 07:29 PM
For most purposes, it's actually best to use 2D sound instead of 3D sound.
Check the import settings on your audioclip, and make sure that '3D sound' is unchecked.
Assuming you left settings default, the 3D sounds don't have a big enough range to reach the audiolistener that is sitting on the Main Camera.
Your answer
![](https://koobas.hobune.stream/wayback/20220613095220im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Audio says it is playing in audiosource but is not... 2 Answers
OneShot Audio not playing 1 Answer
A node in a childnode? 1 Answer
Get an object to play a sound if player rolls over a trigger. 2 Answers
Audio plays when i click F 1 Answer