コガネブログ

平日更新を目標に Unity や C#、Visual Studio、ReSharper などのゲーム開発アレコレを書いていきます

【Unity】オーディオのビートとスペクトラムを検知できる「Unity-Beat-Detection」紹介

はじめに

「Unity-Beat-Detection」を Unity プロジェクトに導入することで
オーディオのビートとスペクトラムを検知できるようになります

使い方

f:id:baba_s:20180103144916p:plain

using UnityEngine;

public class Example : MonoBehaviour
{
    public AudioProcessor processor;

    private void Start()
    {
        processor.onBeat.AddListener( OnBeat );
        processor.onSpectrum.AddListener( OnSpectrum );
    }

    private void OnBeat()
    {
        Debug.Log( "Beat!!!" );
    }

    private void OnSpectrum( float[] spectrum )
    {
        for ( int i = 0; i < spectrum.Length; ++i )
        {
            Debug.Log( spectrum[ i ] );
        }
    }
}

上記のようなコードを記述します

関連記事