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 /
avatar image
1
Question by pumali · Apr 19, 2016 at 06:54 PM · audioclipaudioplayaudio.playoneshotsnapshot

Triggered audio clip deactivates audio snapshot background music - are audio clips and snapshots not able to work simultaneously?

I am making a game that's a souped-up version of the Unity Roll-A-Ball tutorial. When the player-ball completes a puzzle (by collecting 3 pick-ups), it adds a layer of sound (another instrument) to the background music.

My background music is run through the Audio Mixer using Snapshots and the pickup sound effects are Audio Clips through Audio Source. I have no Audio Listeners since I believe they're implicitly within the Audio Mixer. The Snapshots are connected to Audio Sources in the PlayerController object. The Audio Clips are also all attached to the PlayerController. Is there any harm in this? Should the sound effects be attached to the Pickup objects instead?

Each of the pickups are supposed to play 2 feedback noises (correct pickup versus wrong pickup). Whether or not the pickup is the correct one to pickup is run off of a state machine.

The problem is that the pickup sound triggers and then stops the Snapshot that was running in the background. Are Audio Clips and Snapshots not able to work together? Do they interfere in some way?

alt text

using UnityEngine; using System.Collections; using UnityEngine.Audio;

public class PlayerController : MonoBehaviour {

 public string isCollecting = "Beginning";

 public MusicManager Music;

 public AudioClip[] variousClips = new AudioClip[1];
 private AudioSource sound; 
 public AudioMixerSnapshot mainMusic; 

 void Start (){
     sound = GetComponent<AudioSource> (); 
  }

 void OnTriggerEnter(Collider trigger) {

 //Collectibles 1-3 Correct Sequence
     if (isCollecting == "Beginning" && trigger.gameObject.CompareTag("PickUp1")){
         trigger.gameObject.SetActive (false);
         Instantiate(PickUpParticleEffect, gameObject.transform.position, Quaternion.LookRotation(Vector3.up));
         isCollecting = "First";

         //collectible audio sound

         /*sound.clip = variousClips[0]; 
         sound.PlayOneShot(variousClips[0]); 
         if (!sound.isPlaying) {
             //reference to music manager to change the song
             GameObject Player = GameObject.FindGameObjectWithTag ("Player");
             Music = Player.GetComponent<MusicManager> (); **I don't know how to translate from audio clip to snapshot/mixer here**
             Music.tutorialBegin.TransitionTo (0.2f);
                 Music.PuzzleStatus = ("tutorialbegin1"); 
         }*/
     }

     if (isCollecting == "First" && trigger.gameObject.CompareTag("PickUp2")){
         trigger.gameObject.SetActive(false);
         Instantiate(PickUpParticleEffect, gameObject.transform.position, Quaternion.LookRotation (Vector3.up));
         isCollecting = "Second";
     }

     //reference to music manager to change the song
         GameObject Player = GameObject.FindGameObjectWithTag("Player");
         Music = Player.GetComponent<MusicManager> ();
         Music.PuzzleStatus = "Puzzle1";

unity1.jpg (199.8 kB)
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

0 Replies

· Add your reply
  • Sort: 

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

2nd Audio Clip Not Playing 0 Answers

Charged shot audio sequence,How do I get a sequence of sounds to play correctly? 0 Answers

Play audio in editor with a start time. 0 Answers

Getting audio to play on collision 3 Answers

AudioSource (''landing'') play problem 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