- Home /
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?
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";