BPM-based sound trigger
Unity3D 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 :-)
반응형
'Unity3D' 카테고리의 다른 글
Unity3D로 풀3D web mmorpg 만들기 (0) | 2012.09.24 |
---|---|
Unity3d 게임들 (0) | 2012.09.18 |
type 'object' does not support slicing (0) | 2012.09.17 |
[Blender3D] Armature 본 제거와 두개의 본 합체 하기 (0) | 2012.09.13 |
[Blender3d] HotKeys v.2.4 (0) | 2012.09.13 |