- Home /
Question by
DrLlamastein · May 06, 2017 at 06:48 PM ·
arrayaudiogameobjectsarray of gameobjects
Audio Visualisation
I'm trying to make some audio visualisation but it won't work for some reason. It's something to do with the obstacles
GameObject array. But I'm not sure why it doesn't work properly.
obstacles = GameObject.FindGameObjectsWithTag("TileWall");
The obstacles array does get set properly and does have all the obstacles inside of it but then when I use this array in my AudioVisualisation
script it doesn't do anything.
public class AudioVisualisation : MonoBehaviour {
MapGenerator map;
void Update() {
float[] spectrum = new float[512];
AudioListener.GetSpectrumData(spectrum, 0, FFTWindow.Hamming);
for (int i = 0; i < map.obstacles.Length; i++) {
Vector3 prevScale = map.obstacles[i].transform.localScale;
prevScale.y = Mathf.Lerp(prevScale.y, spectrum[i] * 200, Time.deltaTime * 30);
map.obstacles[i].transform.localScale = prevScale;
}
}
}
I tried moving this code over to the MapGenerator
script because that's where the obstacles
array is declared and it works so why won't it work from this script?
public GameObject[] obstacles;
Comment