Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by dmpaskiet · Oct 14, 2010 at 05:41 PM · audioplayclip

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.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

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?

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image dmpaskiet · Oct 14, 2010 at 06:50 PM 0
Share

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.

avatar image lowbloodsugar · Oct 14, 2010 at 07:14 PM 0
Share

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

avatar image dmpaskiet · Oct 14, 2010 at 07:35 PM 0
Share

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

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

No one has followed this question yet.

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges