So last night I was working on adding an achievement to my game. Basically I want it so if the player collects 10 objects at 10 points each without taking any damage an image pops up and a sound plays and they get an "achievement".

What has gone wrong is once this has been fulfilled the image pops up, but the sound doesn't play until they get 11 objects. I can't for the life of me figure out where I went wrong.

Here is the script I'm using:

guiTexture.enabled = false;
var Tada : AudioClip;

function Update () {
if(scorer.scorz == 100 && LifeScript.life == 5){
audio.clip = Tada;
audio.Play();
guiTexture.enabled = true;

}

}

Any help or ideas are as always greatly appreciated.

You are restarting the audio every frame when your score is 100 points. The reason you cant hear anything is that you probably have a millisecond of silence at the beginning of the sound file. This silence is repeated every frame until you surpass the score.

You need to play it only one time: play it the first time you achieve the score. One simple way to ensure this is to add a variable to flag it if its been played yet. You will need to modify your script to do that.

guiTexture.enabled = false; var Tada : AudioClip; private var played:boolean =false;

function Update () { if(scorer.scorz == 100 && LifeScript.life == 5 && !played){ played=true; audio.clip = Tada; audio.Play(); guiTexture.enabled = true; } }

P.S. Do you like your school?