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 hiineededaname · Nov 01, 2021 at 03:32 AM · audiosourceaudioclipmusicsound effects

Music skips when playing sound effects

In the main menu of my game, I want the buttons to make sounds when selected and clicked. The sound effects that play when buttons are selected work fine. However, when a button is clicked that moves to a different section of the menu (which is just another Canvas), the music that's playing on the Main Camera skips forward a little bit then jumps back to where it was before. Here is the script that plays the button sound effects:

 public class ResponsiveMenuButton : MonoBehaviour, ISelectHandler
 {
     [SerializeField] private AudioClip selectClip;
     [SerializeField] private AudioSource soundPlayer;
     [SerializeField] private AudioClip clickClip;
 
     public void OnSelect(BaseEventData eventData)
     {
         if (PlayerPrefs.HasKey("sound"))
         {
             soundPlayer.PlayOneShot(selectClip, PlayerPrefs.GetFloat("sound"));
         }
         else
         {
             soundPlayer.PlayOneShot(selectClip, 0.3f);
         }
     }
 
     public void OnClick()
     {
         if(PlayerPrefs.HasKey("sound"))
         {
             soundPlayer.PlayOneShot(clickClip, PlayerPrefs.GetFloat("sound"));
         }
         else
         {
             soundPlayer.PlayOneShot(clickClip, 0.3f);
         }
     }
 }

The next section of the menu is loaded by making the current menu Canvas inactive and making the next menu Canvas active. The AudioSource that plays sound effects is different from the AudioSource that plays music.

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
Best Answer

Answer by hiineededaname · Nov 01, 2021 at 06:18 PM

Turns out there was some weird issue that happened while I was importing the AudioClip that caused it to mix some of the sounds together, creating the effect. I'm a bit worried as to why that happened but I re-imported the clip and the issue is solved.

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
avatar image
0

Answer by Betina_art · Nov 01, 2021 at 03:05 PM

Hi! Check out this vid by Brackeys on making an Audio Manager: https://www.youtube.com/watch?v=6OT43pvUyfY
He also includes the code for the audio manager.

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 hiineededaname · Nov 01, 2021 at 06:05 PM 0
Share

The method that Brackeys uses in this video would be infeasible with the layout of my game. Thanks for trying to help, though!

avatar image Betina_art hiineededaname · Nov 02, 2021 at 12:30 AM 0
Share

How about getting the WWise plugin? You can use it for managing multiple tracks and also transitioning music to same timestamps in the audio, etc. There's a video on it in unity's official tutorials

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

136 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 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 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 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 avatar image avatar image avatar image avatar image

Related Questions

How to play a playlist of mp3s randomly? 1 Answer

Can play multiple sounds from one audiosource on an object. But cant play sound from audiosource on another? 0 Answers

How to stop music from restarting when reloading scene it began? 0 Answers

How to check if an AudioClip has looped? 0 Answers

SFX fade out and then fade back in? 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