- Home /
Audio Clip Plays 1 turn too late
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.
Answer by lowbloodsugar · Oct 14, 2010 at 06:44 PM
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?
That solved it thank you.
I do like the school. It is lacking in certain areas, but it also excels in some others. I'm just finishing up my freshman year this month, so I've got some time to go. The networking opportunities alone have been awesome.
$$anonymous$$y biggest complaint is we are doing hands on stuff yet actually making games, and I don't think we well until later in the program. So I'm trying to be proactive and get a head start making games, hence the question above.
Good luck and study hard. And my best advice is to not limit your studying to what they $$anonymous$$ch you in school.
Definitely. I've already taken on several projects outside of what is offered in class.
Your answer
Follow this Question
Related Questions
Noob Question: Play Specific Audio 1 Answer
Play Audio Only One at a time? 1 Answer
Randomly play audio 0 Answers
Audio source problem 2 Answers
Playing Sound 2 Answers