- Home /
AudioSource plays noisy audio
Its the first time that it have happend for me, and i don't know why!
Lets take this simple script:
var Exp : AudioSource;
function Update () {
if(Input.GetKey("e"))
Audio.PlayOneShot(Exp);
}
I have attached a audiosource to my object, and placed the clip in the script AudioSoruce and in the audiosource. But when i press "e" It plays a very noisy version of the soundclip!. And its nothing wrong with the soundclip cause when i click Play on Awake the soundclip plays normal.
I have tried making a new project and tested it there, but it still does it. Its first time it have happend to my, and i have done it many times. What is wrong=
Answer by MakeCodeNow · Feb 15, 2014 at 04:21 PM
It's noisy because Input.GetKey will return true every frame that the key is depressed, creating multiple instances of your audio. Try Input.GetKeyUp or Input.GetKeyDown.
Well that explains the example.. :p I thought it was something else so i didn't show the original script. Can you solve this then?
pragma strict
var EXP : AudioClip;
function Start () {
}
function Update () {
if (GameObject.Find("Spaceship").GetComponent(Clickmove2).die == true) { audio.PlayOneShot(EXP);
}
}
You shouldn't really change the question in the comments. If this answer is correct for your question, mark it as answered and then post a new question with your new question. When you do, people will need more info than "can you solve this" where it's not clear what problem you want solved.