Set up spawn seqence based on specified timing

So I’m attempting to make a rhythm game in which enemies are spawned from certain locations based off of the song’s rhythm. I know calculating the rhythm is a whole different subject, but let’s pretend I have a set ‘beat’ calculated. How would I go about spawning enemies according to that ‘beat’? I currently have gameobjects set up as spawners and they spawn prefabs of enemies.

The most logical way I could think to do this and maintain the ability to ‘craft’ the level and spawnings is to create a file and read from the file on ‘beat’.

File Contents: xxxxxTxxxLxxxxB

On a beat> one character is read from the file and that corresponds to what happens (x does nothing, T spawns prefab 1, etc.

File and Song are started at the same time (and the file length is predetermined to make sure there are enough ‘beats’ marked.

So I guess my question is: Is this a ‘good’ way to go about this? And how exactly could I accomplish sequentially reading characters based on a timer of some sort?

That’s not a bad way to store it. There’s so many ways this could be done. You could set up arrays to hold the spawn/beat data too. I like to use CSV files a bit for things like this so I can edit them in a spreadsheet, but there’s no reason a simple text file wouldn’t work. You have to balance: is it easier to write a function to parse the file data into an array for use OR is it easier to write out the arrays and have a function that retrieves the arrays. I do something similar in one of our games for the level data (CSV → parsing function → struct array).

Now you have everything in an array just set up a timer variable that gets activated on beat and keep track of the array’s index.

Psuedo code

Onstart - float spawnTimer = Time.time;

    if beat and (Time.time - spawnTimer > minTimeBetweenSpawns) {
        spawnTimer = Time.time;

I do something similar for animating sprites in our game that is using beat detection.
Beat Detection | Audio | Unity Asset Store is inexpensive and works well. I’ve yet to figure out how to determine the volume/amplitude of the beats, but I’ve not spent much time on it either.

Hope this helps.