FirstPersonController AudioClip component interrupt Background audio from the BackgroundAudio AudioClip
Whenever I press play, my character's footsteps sound is shown on the AudioSource - AudioClip bar, but when I stand still the Background music is played, and whenever I try to move, the Background music stops and restarts only when the character stops moving.
Here's the code: using System.Collections; using System.Collections.Generic; using UnityEngine;
public class MusicPlayer : MonoBehaviour { public AudioClip[] clips; private AudioSource audioSource;
static MusicPlayer Instance;
void Awake()
{
DontDestroyOnLoad(transform.gameObject);
if (Instance != null)
{
Destroy(gameObject);
}
else
{
Instance = this;
DontDestroyOnLoad(gameObject);
}
}
void Start()
{
audioSource = FindObjectOfType<AudioSource>();
audioSource.loop = false;
}
private AudioClip GetRandomClip()
{
return clips[Random.Range(0, clips.Length)];
}
void Update()
{
if (!audioSource.isPlaying)
{
audioSource.clip = GetRandomClip();
audioSource.Play();
}
}
}
This is put on my Music Player Empty Game object and there is also another Audio source on the FPS controller. Is there a way I can have my playlist of songs playing without getting interrupted by the footstep sound?
Your answer
![](https://koobas.hobune.stream/wayback/20220612224443im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
AudioSource does not play upon entering trigger 1 Answer
Cracking at end of audio? 0 Answers
Audio Cutting Out Unexplainably 1 Answer
Change Audio Mixer through script for every scene 0 Answers
Playing looped sound while holding button is distorted 2 Answers