Unity3D
BPM-based sound trigger
일등하이
2012. 9. 18. 10:52
반응형
BPM Counter / step sequencer
I've just cobbled together a very basic BPM-based sound trigger / sequencer.
Attach the script to an object with an audiosource (preferably a drum sound - kick, snare, hat) and in the inspector you can set the BPM, the notes on/off pattern, and the step size.
I've tried a few 4/4 combos around 120 bpm and it seems ok, though I suspect the timing is not as tight as it could be.
Is there a better method for solid timing than calling InvokeRepeating?Code:
#pragma strict #pragma implicit #pragma downcast var BPM : float = 120.0; private var t : float = 0.0; var beatgrid : int[]; // in inspector assign 0/1 for beat on/off on individual step private var beatmarker : int=0; var steps : int = 4; t = BPM/60.0; // how many beats per second t=(1.0/t)/steps; // divide by steps beatmarker=0; } function Trigger () { beatmarker+=1; if (beatmarker>beatgrid.length-1)beatmarker=0; }
Feel free to use / modify :-)
반응형