void FixedUpdate()
{
transform.position = player.transform.position + offset;
if (!playing)
{
time = 0.0f;
playing = true;
scratchIndex = Random.Range(0, scratchesLenght);
audio.clip = scratches[scratchIndex];
scratchLenght = scratches[scratchIndex].length;
float pauseModifier = 1.0f - audio.volume;
pauseLenght = Random.Range(2.0f * pauseModifier + 0.1f, 5.0f * pauseModifier + 0.1f);
audio.Play();
}
else
{
time += Time.fixedDeltaTime;
if (time > scratchLenght + pauseLenght)
{
playing = false;
}
if (time > scratchLenght)
{
audio.Stop();
}
}
}