I’m trying to make a audio visualizer in Unity. Want a sphere to resize as reaction on the music.
I keep getting this error: “IndexOutOfRangeExeption: Array index is out of range.”
Ok, because I’m new to this scripting thing, I don’t know how to fix it. t’s probably really simple, but we al got to start somewhere, right?
So here is my script:
using UnityEngine;
using System.Collections;
public class Spechtrum : MonoBehaviour {
public GameObject[] sphere;
public int numberOfObjects3 = 20;
void Start () {
sphere = GameObject.FindGameObjectsWithTag ("sphere");
}
void Update () {
float[] mid = AudioListener.GetSpectrumData (1024, 0, FFTWindow.Hamming);
//The next line is the error line.
for (int i = 0; i < numberOfObjects3; i++) {
Vector3 previousScale = sphere *.transform.localScale;*
previousScale.y = mid * 10;
previousScale.x = mid * 10;
previousScale.z = mid * 10;
_ sphere .transform.localScale = previousScale;
* }
}
}*
I was wondering if anyone could help me?_