UIButton not playing sound on click,UI Button not playing sound and blocking script
I'm making a game where you have several audio channels (each a group on an AudioMixer) and a deck of card with beats that you drop on the channels and they get added to the Mixer. It works by sending the AudioSource of the card to the AudioSource of the GameObject that represents the channel and then destroying the card, here's the code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Audio;
public class ManageChannel : MonoBehaviour
{
public AudioSource thisAudioSource;
bool chequeo;
string Nombre;
public AudioMixer audioMixer;
public void AsignaCanal (){
Nombre = this.name; // tomo el nombre del canal actual
thisAudioSource = this.GetComponent<AudioSource>();
var carta = this.transform.GetChild(0); // llamo a la carta hija de este objeto
thisAudioSource.clip = carta.GetComponent<AudioSource>().clip;
thisAudioSource.outputAudioMixerGroup = audioMixer.FindMatchingGroups(Nombre)[0]; // asigno al AudioSource el grupo correspondiente
}
public void comienzaAudio (){
if (!thisAudioSource.isPlaying){
thisAudioSource.Play();
}
else {
thisAudioSource.Stop();
}
}
// Start is called before the first frame update
void Start()
{
chequeo = true;
}
// Update is called once per frame
void Update()
{
if (this.transform.childCount != 0 && chequeo) {
AsignaCanal();
chequeo = false;
thisAudioSource.Play();
}
}
}
What i'm trying to do now is to build a play button for each channel (i already have one for the master that works) but how I implemented it it's not giving results; I create an UIButton and then add to the OnClick() component on the inspector the GameObject representing the channel, then i use the ComienzaAudio() function from the script i wrote for the OnClick(), but nothing happens. And also i've noticed that when the button is on the channel (it's a panel) when i drop the cards the AudioSource of the card doesn't gets sent to the channel.
Any help would be appreciated. It's my first time asking here so if i need to provide additional information or screencaps, i'd gladly do. Thanks!