- Home /
My soundclip is noisy?
I made this script so when i die, et playes a exploding sound effect. But when i die and the sound plays, the sound is like a noisy version of the sondclip. I found out it was because that keept restarting the clip every frame.
But i don't know how to fix it. Please help.
var EXP : AudioClip;
function Start () {
}
function Update () {
if (GameObject.Find("Spaceship").GetComponent(Clickmove2).die == true)
{
audio.PlayOneShot(EXP);
}
}
Answer by getyour411 · Feb 16, 2014 at 11:08 AM
some pseudo code
var isPlaying : bool;
Awake()
isPlaying = false;
Update()
if(yourExistingCondition && !isPlaying) {
playSound
isPlaying = !isPlaying;
(at some point you'd set it back to false)
Basically you need some sort-of control structure to prevent it from starting every frame.
Edit: converted from comment to Answer
If you happen to see this again, please click Accept Solution to close this.
Answer by Commander5518 · Feb 15, 2014 at 09:47 PM
try this....
#pragma strict
var explosion : AudioSource;
function Update(){
if(GameObject.Find("SpaceShip").GetComponent(Clickmove2).die == true){
explosion.Play();
}
}
Create an audiosource on your spaceship then add the clip you want to play to that. then assign the audiosource to the variable of that script in the inspector.
I did it, but now it sounds even worse. And this error came:
The variable explosion of 'Explosion' has not been assigned. You probably need to assign the explosion variable of the Explosion script in the inspector.
But i have assigned it.