Looped AudioSource stops looping after 5 or so seconds

32 Views Asked by At

For the life of me I can't understand why it stops looping. I have an engine acceleration script that works great, except for the fact that it stops looping after a certain amount of time. I'm only calling the audiosource to be stopped if the user presses a button, it should work just fine. It has worked before implementing this too, I've no idea what breaks it.

private void PlayAccelerateSound()
{
    m_audioSource2.loop = true;

    m_audioSource2.clip = m_engineSound;
    if (!alreadyPlayed)
    {
        m_audioSource2.PlayOneShot(m_audioSource2.clip);
        alreadyPlayed = true;
    }

    if (rb.velocity.x < minPitch)
    {
        m_audioSource2.pitch = minPitch;
    }
    else if (rb.velocity.x > maxPitch)
    {
        m_audioSource2.pitch = maxPitch;
    }
    else
    {
        m_audioSource2.pitch = rb.velocity.x;
    }
}
1

There are 1 best solutions below

0
alt4s On BEST ANSWER

Fixed it by using m_audioSource2.Play() instead of m_audioSource2.PlayOneShot(m_audioSource2.clip).