Question by
KiritoSAO2 · Jan 06, 2017 at 08:05 PM ·
scripting problemdetectionnoobrhythm
How do you script Beat Detection?
I'm found this script but need a better example of implementing the interface on an object being notified when a beat is detected. Any one who's used this script before, please give me whatever examples or tips you got. I'd really appreciate it.
This is my first time using a script like this. So go easy on me. My goal is to make a car change color to the beat.
Here's the script:
using UnityEngine;
using System;
public class Example : MonoBehaviour, AudioProcessor.AudioCallbacks
{
void Start()
{
AudioProcessor processor = FindObjectOfType<AudioProcessor>();
processor.addAudioCallback(this);
}
void Update()
{
}
public void onOnbeatDetected()
{
Debug.Log("Beat!!!");
}
public void onSpectrum(float[] spectrum)
{
for (int i = 0; i < spectrum.Length; ++i)
{
Vector3 start = new Vector3(i, 0, 0);
Vector3 end = new Vector3(i, spectrum[i], 0);
Debug.DrawLine(start, end);
}
}
}
Comment
Your answer
