Enable/Disable UI Button (I Need Help!)

Hello eveyone.
I’m making a game in Unity that is based on Clicking…

I have 8 buttons, when you click on the first button you need to hear the sound playing (I did thet for the sound), and when you click on the first button again when the sound is play nothing needs to happen is needs to continue the song until in ends…
And when you click on the next 7 buttons when the first on is playing nothing needs to happen until the song is over for the first button…

Can someone please help I’m really stuck and can’t continue with my game…

Thank you very much! :slight_smile:

So you want 1 Button that is playing a song and 7 buttons that do absolutly nothing?

Maybe try describing your problem different. It’s not clear what you want and whats the problem.

it sounds like he wants is. when a btn is pressed it needs to play a song, but if a song is already playing, then do nothing.

@DrakDustM do some research on AudioSource.isPlaying

IE:
if (!audio.isPlaying)
{
audio.Play();
}

@johne5
This code is for the song so it play’s only one time?

And the other problom is for the button’s…

If you have 3 button’s and you press the first button the other 2 need to be frozen and not accessible for clicking.

Something live this.
You have 5 button’s for Guitar and when you press the Guitar 1 button the other’s need to be Disabled.

you need to have a script that toggles the button.interactable

public Button GuitarBtn2;
public Button GuitarBtn3;
public Button GuitarBtn4;
public Button GuitarBtn5;

public void btnClicked()
{
GuitarBtn2.interactable = false;
GuitarBtn3.interactable = false;
GuitarBtn4.interactable = false;
GuitarBtn5.interactable = false;
}
1 Like

@johne5
Oke Thank you werry much :smile:
You helped me a loot :smile:

can you post the updated code that you’re using? I can help with in freezing the buttons after the song is complete

this is what I would do based the past code I posted

public Button GuitarBtn1;
public Button GuitarBtn2;
public Button GuitarBtn3;
public Button GuitarBtn4;
public Button GuitarBtn5;
AudioSource audioSource;
 
public void btnClicked()
{
    audioSource.Play();
}
void Start()
{
    audioSource = GetComponent<AudioSource>();
}
void Update()
{
    if (audioSource.isPlaying)
    {
    GuitarBtn1.interactable = false;
    GuitarBtn2.interactable = false;
    GuitarBtn3.interactable = false;
    GuitarBtn4.interactable = false;
    GuitarBtn5.interactable = false;
    }else
    {
    GuitarBtn1.interactable = true
    GuitarBtn2.interactable = true
    GuitarBtn3.interactable = true
    GuitarBtn4.interactable = true
    GuitarBtn5.interactable = true
    }
}