sound on button hold only/pause other sounds
Hello
I have 6 buttons. 2 of the buttons i'm trying to make it so when they are held, they play a sound and when released it stops the sound. Also, when either of those two buttons are pressed, they pause any sounds coming from the other 4 buttons. This is my script, any ideas? Thanks in advance <3
using UnityEngine;
public class PlayTheSound : MonoBehaviour
{
new public AudioSource sound;
private bool isPlaying;
public void PlaySound()
{
if (isPlaying)
{
sound.Stop();
isPlaying = false;
}
else
{
foreach (AudioSource as in FindObjectsOfType<AudioSource>())
{
as.Stop();
}
sound.Play();
isPlaying = true;
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Disabling UI while audio is playing 0 Answers
Unity 5 buttons not interacting within a nested canvas 1 Answer
how could i change this code so the restart function can be activated via button? 0 Answers
How Do You Make GUI Buttons Remain in the Same Place No Matter the Resolution? 1 Answer
Unity thinks I'm holding up and left on a joystick 3 Answers