x


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.

more ▼

asked Oct 14, 2010 at 05:41 PM

dmpaskiet gravatar image

dmpaskiet
366 34 33 49

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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?

more ▼

answered Oct 14, 2010 at 06:44 PM

lowbloodsugar gravatar image

lowbloodsugar
603 26 22 30

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.

My 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.

Oct 14, 2010 at 06:50 PM dmpaskiet

Good luck and study hard. And my best advice is to not limit your studying to what they teach you in school.

Oct 14, 2010 at 07:14 PM lowbloodsugar

Definitely. I've already taken on several projects outside of what is offered in class.

Oct 14, 2010 at 07:35 PM dmpaskiet
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x4911
x1691
x349
x115

asked: Oct 14, 2010 at 05:41 PM

Seen: 1463 times

Last Updated: Oct 14, 2010 at 05:41 PM