I'm trying to reproduce a sound clip on the AudioSource of a game object by using the .Play method. What i'm trying to do is a card game of sorts, but with each card being a different section of a song of a genre. I combine different cards with different genres and when i press play, the combination should start playing, but now when the play button is pressed, only noise comes out. The code for the start method looks like this:
public class AudioStart : MonoBehaviour
{
AudioSource thisAudioSource;
// Start is called before the first frame update
void Start()
{
thisAudioSource = this.GetComponent<AudioSource>();
}
// Update is called once per frame
void Update()
{
if (playButton.playPressed) {
thisAudioSource.Play();
}
else {
thisAudioSource.Stop();
}
}
}
The way i'm doing it is by having a button that on click changes a bool to true or false depending if there is sound playing (the truth check on the if statement). The AudioSource outputs to an AudioMixer on a specific group under the master group (which group depends on the slot that the card is dropped in). The AudioStart script is attached to different game objects with a different audio clip each. I've also noticed that when i try to reproduce two cards, only one AudioSource gets played. Any help would be appreciated. Thanks!
PlayOneShot
. Without parenthesis, it won't even compile. Are you usingPlay
orPlayOneShot
? It's hard to diagnose a bug if you don't share the actual code with the bug. \$\endgroup\$Play()
insideUpdate()
. As far as I remember,Play()
will start from beginning of audio clip each time it is called. Try this:if (playButton.playPressed && !thisAudioSource.isPlaying)
\$\endgroup\$