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 bpierpont89 · Oct 07, 2015 at 11:20 PM · audiosoundaudiosourceaudioclipmusic

Audio Cutting Out Unexplainably

I'm trying to implement a 15-song soundtrack to play in my game. I have a script that randomly chooses the next song to play when the song currently playing is finished. It works for the first few songs during the playing of the game, but then it starts to act weird. The audio will cut out more and more frequently as it plays, skipping to the next song. The part where it skips in the songs is always different and Unity recognizes the song's length correctly, so the problem isn't there. I converted my files from .mp3 to .ogg as suggested on other posts and there was no change in the cutting of tracks. I changed "audio.Play()" to "audio.PlayOneShot()". I also messed with the settings a bunch, yet nothing seems to help. The songs are the only audio clips being played in the game, so they shouldn't be overloading the system or anything either. In stats, right as the audio skips and goes to the next song, there is a visible increase in db, from "-11 db" to "-80 db." Is my audio messed up? Is it my audio playing script? Is it just Unity? Any help would be greatly appreciated.

Here's my script:

  #pragma strict
  
  public var Pre : AudioClip;
  public var Con : AudioClip;
  public var Sky : AudioClip;
  public var Fig : AudioClip;
  public var The : AudioClip;
  public var Imp : AudioClip;
  public var Dis : AudioClip;
  public var Conn : AudioClip;
  public var Hard : AudioClip;
  public var End : AudioClip;
  public var Rea : AudioClip;
  public var Sta : AudioClip;
  private var SoundSource : AudioSource;
  public var Goi : AudioClip;
  public var Emp : AudioClip;
  public var Clo : AudioClip;
  var playNow: boolean = false;
  
  function Awake() { DontDestroyOnLoad(gameObject); 
  SoundSource = gameObject.AddComponent(AudioSource); 
  SoundSource.playOnAwake = false; 
  SoundSource.rolloffMode = AudioRolloffMode.Logarithmic;
  SoundSource.loop = false;
  SoundSource.priority = 0;
  }
  
  var randomplay : float;
  
  function Start() { 
  randomplay = Random.Range(1,16);
  audioer();
  }
  
  function audioer(){
      if (randomplay == 1) {
          SoundSource.clip = Pre; 
          SoundSource.PlayOneShot(Pre); 
          yield WaitForSeconds(Pre.length);
              Start();
  
                  }
      if (randomplay == 2) {
          SoundSource.clip = Con; 
          SoundSource.PlayOneShot(Con); 
          yield WaitForSeconds(Con.length);
              Start();
  
  
          }
      if (randomplay == 3) {
          SoundSource.clip = Sky; 
          SoundSource.PlayOneShot(Sky);
          yield WaitForSeconds(Sky.length);
              Start();
  
  
          }
      if (randomplay == 4) {
          SoundSource.clip = Fig; 
          SoundSource.PlayOneShot(Fig);
          yield WaitForSeconds(Fig.length);
              Start();
  
  
          }
      if (randomplay == 5) {
          SoundSource.clip = The; 
          SoundSource.PlayOneShot(The); 
          yield WaitForSeconds(The.length);
              Start();
  
  
          }
      if (randomplay == 6) {
          SoundSource.clip = Imp; 
          SoundSource.PlayOneShot(Imp); 
          yield WaitForSeconds(Imp.length);
              Start();
  
  
          }
      if (randomplay == 7) {
          SoundSource.clip = Dis; 
          SoundSource.PlayOneShot(Dis); 
          yield WaitForSeconds(Dis.length);
              Start();
  
  
          }
      if (randomplay == 8) {
          SoundSource.clip = Conn; 
          SoundSource.PlayOneShot(Conn); 
          yield WaitForSeconds(Conn.length);
              Start();
  
  
          }
      if (randomplay == 9) {
          SoundSource.clip = Hard; 
          SoundSource.PlayOneShot(Hard); 
          yield WaitForSeconds(Hard.length);
              Start();
  
  
          }
      if (randomplay == 10) {
          SoundSource.clip = End; 
          SoundSource.PlayOneShot(End); 
          yield WaitForSeconds(End.length);
              Start();
  
  
          }
      if (randomplay == 11) {
          SoundSource.clip = Rea; 
          SoundSource.PlayOneShot(Rea); 
          yield WaitForSeconds(Rea.length);
              Start();
  
  
          }
      if (randomplay == 12) {
          SoundSource.clip = Sta; 
          SoundSource.PlayOneShot(Sta); 
          yield WaitForSeconds(Sta.length);
              Start();
  
  
          }
      if (randomplay == 13) {
          SoundSource.clip = Goi; 
          SoundSource.PlayOneShot(Goi); 
          yield WaitForSeconds(Goi.length);
              Start();
  
  
          }
      if (randomplay == 14) {
          SoundSource.clip = Emp; 
          SoundSource.PlayOneShot(Emp); 
          yield WaitForSeconds(Emp.length);
              Start();
  
  
          }
      if (randomplay == 15) {
          SoundSource.clip = Clo; 
          SoundSource.PlayOneShot(Clo); 
          yield WaitForSeconds(Clo.length);
              Start();
  
  
          }
      }
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
-1

Answer by MadDevil · Oct 08, 2015 at 05:06 AM

@bpierpont89

I cant find anything wrong with your code, but I would suggest you use switch case instead of so many if statements.

and don't forcefully call start method as inbuilt unity methods sometimes messes up the execution order of the code if called forcefully.

Comment
Add comment · Show 1 · 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 bpierpont89 · Oct 08, 2015 at 10:27 PM 0
Share

@$$anonymous$$adDevil , Thanks for replying! I tried both of your suggestions. Neither of them add any improvement to the skipping of the soundtrack. What should I do?

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

33 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Audio is way too soft on mobile but alright in Unity Editor! 0 Answers

Need help: new sound isnt played correctly anymore 2 Answers

Cracking at end of audio? 0 Answers

Second AudioClip won't play 0 Answers

Second AudioClip won't play 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