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 CallToAdventure · May 02, 2011 at 01:33 PM · soundscore

Play Sound on Score

I am trying to play a sound when a score is reached and I can't get anywhere.

var Score : int =0;

var ScoreSound : AudioClip;

function Update () {

guiText.text = "Score "+Score;

if(Score >= 1000)

    Boo();

}

function Boo(){

    audio.clip = ScoreSound;
    audio.PlayOneShot(ScoreSound);
    yield WaitForSeconds (audio.clip.length);
    yield WaitForSeconds (5);
    Application.LoadLevel ("WinMenu"); 

}

I think the problem is with if(Score >= 1000) - I tried == but no luck. The sound will keep playing because the score is greater or equal than 1000.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Kourosh · May 02, 2011 at 02:07 PM

in Boo() function add this line:

Score =0;

it'll immediately stop the if statement from calling the function every frame.

Comment
Add comment · Show 2 · 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 CallToAdventure · May 02, 2011 at 02:33 PM 0
Share

It works sure enough but it will reset my score. I have other sounds playing at smaller score values before loading the level when reaching a high score.

avatar image Kourosh · May 02, 2011 at 02:52 PM 0
Share

$$anonymous$$ Poirot answer should be fine. Also if you can have 2 variables storing score value one to show on your guiText and one for reseting after conditions applied (the boo sound played).

avatar image
0

Answer by M Poirot · May 02, 2011 at 02:43 PM

you should add an if statement which is true when the sound hasn't been played and which truns false when the sound is played.

var Score : int =0; var ScoreSound : AudioClip;

function Update () { guiText.text = "Score "+Score; if(Score >= 1000) Boo(); }

var playSound = true;

function Boo(){ if(playSound==true); { audio.clip = ScoreSound; audio.PlayOneShot(ScoreSound); yield WaitForSeconds (audio.clip.length); yield WaitForSeconds (5); Application.LoadLevel ("WinMenu"); playSound = false; } }

I haven't tested it but I thought it would world

Comment
Add comment · Show 5 · 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 CallToAdventure · May 02, 2011 at 02:54 PM 0
Share

I get this though from what it looks it should work: Assets/PiratesHat!/PiratesHatAssets/Scripts/TestScore.js(43,15): BCE0044: expecting :, found '='.

avatar image Kourosh · May 02, 2011 at 02:58 PM 0
Share

theres an extra ";" after (playSound==true) which should be removed.

avatar image CallToAdventure · May 02, 2011 at 03:03 PM 0
Share

I missed that one :)

avatar image CallToAdventure · May 02, 2011 at 04:17 PM 0
Share

It works awesomely; however, I don't understand how the >= works; Once I play the sound once (score >= 1000) I cannot repeat it at 2000, 3000 or any other higher score.

avatar image M Poirot · May 03, 2011 at 03:43 PM 0
Share

= means if your score equals or is bigger than thousand the sound should be played.

When your score turns 2000 the playSound var can be turned on again, which will get you the script which im posting below

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

Score system in C# [fixed] 1 Answer

Image popup when score reaches 10 C# 1 Answer

No sound in my video after capturing my screen? 0 Answers

Jumping sound not working after respawning 1 Answer

Get Audio from Speakers 0 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