Playing an audio "rhytmically" gets out of sync

Hi,

I’m trying to make a metronome in my game so with 60 BPM, I would hear 1 beat per second (or 60 per minute, BPM). Problem is, when play my sound effect on the desired times more than a couple seconds, it slowly gets slower or faster and out of sync with an actual metronome.

I tried playing my sound with either with audioSource.PlayOneShot() or audioSource.Play().

Here is my code link text

Thanks

In line 15 it should say:

    nextBeatRemainingTime = nextBeatRemainingTime + beatPerSecond;

That way you are also considering the time this update cycle is already behind the exact beat timing.