- Home /
Distorted audio clips. Help please.
I have a class project do in less than 24 hours and all of my sound effects are playing distorted. Any audio I use for bg music is fine though. For example, a door sound is played when opening a door but it is stretched out and computerized sounding. I have tried wav, mp3, ogg, various compression settings, 3d/not 3d, for mono, native format/compressed format. I have no idea what's going on. Here is a script I am using to open a door and it calls the sound, idk if it's the script?
var sound: AudioClip; var Scene : String; static var inTrigger = 0;
function OnTriggerEnter(other : Collider) { if(other.name == "Player") { inTrigger = 1; }
}
function OnTriggerStay (other : Collider) { if(other.name == "Player") { inTrigger = 1; }
//turns on motor to open the door when player hit fire2 and is near door
if(Input.GetButton("Fire2") && other.name == "Player")
{
this.hingeJoint.useMotor = true;
audio.PlayOneShot(sound);
yield WaitForSeconds (2);
LoadNewLevel();
}
}
function LoadNewLevel () { //if (Application.CanStreamedLevelBeLoaded ("Basement") && ) //{ inTrigger = 0; Application.LoadLevel (Scene);
// } }
function OnTriggerExit(other:Collider) {
inTrigger = 0;
}
function OnGUI () { if(inTrigger) { // Make a background box GUI.Box (Rect (Screen.width / 2 ,Screen.height / 2,150,50), "Press E to open door"); }
Does it sound ok in the preview pane? (i.e. select the sound in the Project pane, then in the Inspector at the bottom there is a Preview pane with a little Play button)
Could be to do with the audio listener, is there more than one? Are you standing far away?
Yeah, it sounds just fine in the preview pane.
I don't think there is more than one listener in the scene but I'll go double check. The sounds play when a door opens or the player picks up an item so the player is generally very close to the audio source.
no idea. All the other sounds play just fine, like bg music. It's just when my scripts call a sound to play for a particular action that they are completely distorted...
Answer by jonas-echterhoff · May 11, 2010 at 08:01 PM
From what it looks to me, as you are using Input.GetButton(), you will start playing the sounds every frame, as long as the button is hold down - so, you really have many instances of the sound playing at the same time. Try using Input.GetButtonDown() instead, which will only be "true" once, when the button is first pressed.
Yup, that did the trick! Thanks for the answer Jonas, this was driving me crazy as I am not a programmer at heart.
Answer by Jayland · Dec 17, 2011 at 02:07 AM
What if I wrote a script sayin "If the player is a certain dist of the enemy, play audio.PlayOneShot(sound);" I have the same problem. How do I fix this?
Your answer
Follow this Question
Related Questions
Audio trigger by key press - problems 1 Answer
how to play audio at a given time. 2 Answers
Play music troughout whole game in js 1 Answer
Screenshot Movie with Audio Capture 1 Answer