1_创建一些方块
2_创建脚本
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Auds1 : MonoBehaviour
{
public GameObject[] obj;
public AudioClip audionew;
private string devices;
float[] date=new float[1280];
private void Start()
{
devices = Microphone.devices[0];
audionew = Microphone.Start(devices, true, obj.Length, 44100);
}
private void Update()
{
int ofset = Microphone.GetPosition(devices)-obj.Length;
audionew.GetData(date, ofset);
for (int i = 0; i < obj.Length; i++)
{
obj[i].gameObject.transform.localScale = new Vector3(1, date[i] * 15, 1);
}
}
}