I’m doing an experimentation with my platform game and I want to see if I can move my platforms based on music. I’ve tried getting the music frequency or channels but there seems to be no change in it.
using UnityEngine;
using System.Collections;
public class music : MonoBehaviour {
private float music_vol_peak;
private AudioSource audioHolder;
// Use this for initialization
void Start (){
audioHolder = GameObject.FindGameObjectWithTag("Music").GetComponent<AudioSource>();
}
// Update is called once per frame
void Update () {
music_vol_peak = audioHolder.clip.frequency;
//Debug.Log(music_vol_peak);
}
}
Thats the code I’ve been using. Is there anyway to get something like the right and left peak volume channels?
using UnityEngine;
using System.Collections;
public class music : MonoBehaviour {
private AudioClip music_data;
private AudioSource audioHolder;
// Use this for initialization
void Start (){
audioHolder = GameObject.FindGameObjectWithTag("Music").GetComponent<AudioSource>();
music_data = audioHolder.clip;
float[] samples = new float[audio.clip.samples * audio.clip.channels];
audio.clip.GetData(samples, 0);
int i = 0;
while (i < samples.Length) {
samples[i] = samples[i] * 0.5F;
++i;
}
audio.clip.SetData(samples, 0);
Debug.Log(music_data);
}
// Update is called once per frame
void Update () {
}
}