A sound constantly loop at the start of the audioclip

I have a sound I want to play when two condition are true. I did this many time before but for some reason I have an instance where the sound just loop at the first frame of the audioclip instead of just playing completly.

AudioSource audioOne;
public GameObject buttonSource;

// Use this for initialization
void Start () {
audioOne = buttonSource.GetComponent ();
}

// Update is called once per frame
void Update () {
if (thing==true && thing==true)
{
audioOne.Play();
}

My script look like this,

To be honest its a recurring problem that happen to a lot of audiosource in the scene(But not all)
I really don’t know the probleme any idea?

Thanks

are the audio clips set to loop?

Same as this problem

When both things become true, they remain true I assume, which means that unity will try to play the audio file every frame.

Probably you want something more like

if (thing==true && thing==true && !audioOne.isPlaying)

Check if the audiosource is already playing a file before trying to feed it another one.
I assume “isPlaying” is fixed by now, I remember some people had problems with this and it was spotty, but that was a long time ago.

You could also reset one or both of the variables that push you into that code which plays the file

if (thing==true && thing==true)
{
thing = false;
audioOne.Play();
}

You should use a combination of these methods if you’re not just mocking something up.

I had a similar problem to what NA-RA-KU mentioned when using isPlaying, and got around it by the solution he suggested below that which was to just use a bool soundPlaying and adjust it accordingly. Worked with no problems at all