Rhythm game bpm not working properly

I wrote the following code for my Rhythm game, but there seems to be some issues

=========================================================

public class gm : MonoBehaviour {

List whichnote = new List() {1,2,3};

public int notemark = 0;

public Transform qObj;

public string timerReset=“y”;

public float xPos;

public static int Combo = 0;

public Transform Tencombo;

public string Combospawn = “n”;

public static float totalscore = 0;

// Use this for initialization
void Start () {

}

// Update is called once per frame
void Update()
{

if (timerReset == “y”)
{
StartCoroutine(spawnnote());
timerReset = “n”;
}

if ((Combo==10) && (Combospawn==“n”))
{
Combospawn = “y”;
Instantiate(Tencombo, new Vector3(0.16f, 3.15f, 1.05f), Tencombo.rotation);
}
}

IEnumerator spawnnote()
{
yield return new WaitForSeconds(0.34285f);

if (whichnote [notemark] == 1)
{
xPos = -50f;
}
if (whichnote [notemark] == 2)
{
xPos = -13f;
}
if (whichnote [notemark] == 3)

=========================================================================

To summarize, the game spawns a note in whatever position you list it to do, waits for however many seconds you tell it to (for example: mine is .34285, which is 175 bpm), then spawns the next note in the list. However, in-game the notes spawn at different times than I tell it to do, making the song out of sync with the game.

If you know the purpose of this, a fix, or another way of calculating bpm, please tell me. Any help is appreciated.

A rhythm game needs a master clock source to keep the audio and visuals in sync. I suspect (upon a cursory glance at your example code) that your timing issue is related to the fact that you’re relying on Update() and WaitForSeconds() as your clock. Update() does not get called at consistent time intervals due to frame rate variability. WaitForSeconds() has some timing related considerations of its own which are described in the documentation:

Thanks for the help, are there any tutorials on a master clock source?

@PalPenny check your other topic where I responded on this. Coding a stable bpm? - Unity Engine - Unity Discussions