Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by Bibbys_Designs · Apr 19, 2016 at 11:40 AM · script.gameaudio.playoneshot

audio keeps playing despite oneShot

I have created a script (that has some more in it) but i have displayed the important parts that are involved with the problem. The script allows a block to display a different colour depending on what random number it's given. For some reason when i select the good blocks they don't play the audio clip just once it constantly repeats despite the use of oneShot.

 var backspin                 : boolean;
 public var GoodSound         : AudioClip;
 
  
 function Update () {
 
 if(backspin == true){
             retexture -= Time.deltaTime;
             if(retexture < 0){    
                 if(number < 4){
                     Bad ();
                 }
                 if(number >= 4){
                     Good ();
                     audio.PlayOneShot (GoodSound);
                 }
             }
         }
 }
 
 function OnMouseDown () {
     backspin = true;
 }

can anyone help? i can put the whole script in if needs be, just didn't want too put in too much.

Comment
Add comment · Show 1
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 m4rtini · Apr 19, 2016 at 11:59 AM 0
Share

I believe PlayOneShot only makes it so a new call won't restart the sound. You would have to do some more if you only want it to play once. For example you could create a hasPlayed boolean that you set to true when starting the sound, and reset it to false somewhere else (For example on mouse up) Then you could do if(backspin == true && hasPlayed == false). backspin could potentially be used for the same purpose, i see no place where you set it to false so the if check in update would always be true after the first click. $$anonymous$$aybe set it to false when starting the sound?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by aditya · Apr 19, 2016 at 12:07 PM

in Update after checking your backSpin for true simply set it back to false

  function Update () {
  
  if(backspin == true){
              backspin = false;
              retexture -= Time.deltaTime;
              if(retexture < 0){    
                  if(number < 4){
                      Bad ();
                  }
                  if(number >= 4){
                      Good ();
                      audio.PlayOneShot (GoodSound);
                  }
              }
          }
  }
Comment
Add comment · 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

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How do I code one Ball to be a universal player? 2 Answers

I need help making a 2 player car game 1 Answer

Hi, we are currently doing our thesis, it's a quiz type of game. My question is, how do I collect the scores from four different scripts and output them on the menu page? 1 Answer

Making shield break when hit with some types of ammo 0 Answers

Hey guys I need help for a score broad system. 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