Skip to content

Instantly share code, notes, and snippets.

@Demkeys
Created May 23, 2020 06:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Demkeys/d92c016d5efd6265ec951242a9a2dc07 to your computer and use it in GitHub Desktop.
Save Demkeys/d92c016d5efd6265ec951242a9a2dc07 to your computer and use it in GitHub Desktop.
Simple audio visualizer script to be used with VRChat Udon and UdonSharp.
// Audio Visualize script:
// -Assign a prefab asset to the prefab01 field in the Inspector.
// -Set YScale value in Inspector.
// -Assign a audio source to the audSource field in the Inspector.
using UdonSharp;
using UnityEngine;
using VRC.SDKBase;
using VRC.Udon;
public class AudVisUScript01 : UdonSharpBehaviour
{
public GameObject prefab01;
Transform[] transArr01;
public float YScale;
public AudioSource audSource;
void Start()
{
transArr01 = new Transform[64];
for(int i = 0; i < transArr01.Length; i++)
{
GameObject go = VRCInstantiate(prefab01);
transArr01[i] = go.transform;
transArr01[i].parent = transform;
}
}
void Update()
{
float[] spectrumData = new float[transArr01.Length];
audSource.GetSpectrumData(spectrumData, 0, FFTWindow.Triangle);
for(int i = 0; i < spectrumData.Length; i++)
{
transArr01[i].localPosition = new Vector3(i,transform.position.x, transform.position.z);
transArr01[i].localScale = new Vector3(1,spectrumData[i]*YScale,1);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment