Question by
whitew0lf5 · Apr 10, 2017 at 12:40 PM ·
c#animationaudio
Can anyone find my mistake?
So I've been following a tutorial on how to make a circle of blocks in to an audio visualizer. Only problem is the code he used seems to be either out of date or obsolete. I have a series of syntax errors on line 30 saying they expected semicolons, closed parenthesis, and that one of the parentheses is unexpected.
the line tat has the problem is the line stating "for (int i = 0, i < numberofObjects; i++) {"
code is as follows:
using System.Collections;
using UnityEngine;
public class Spectrum : MonoBehaviour {
// C#
// Instantiates a prefab in a circle
public GameObject prefab;
public int numberOfObjects = 20;
public float radius = 5f;
public GameObject[] cubes;
public float maxTime;
public float currentTime;
void Start() {
for (int i = 0; i < numberOfObjects; i++) {
float angle = i * Mathf.PI * 2 / numberOfObjects;
Vector3 pos = new Vector3(Mathf.Cos(angle), 0, Mathf.Sin(angle)) * radius;
Instantiate(prefab, pos, Quaternion.identity);
}
cubes = GameObject.FindGameObjectsWithTag ("cubes");
}
// Update is called once per frame
void Update () {
float[] samples = new float[1024]; AudioListener.GetSpectrumData (samples, 0, FFTWindow.Hamming);
for (int i = 0, i < numberofObjects; i++) {
Vector3 previousScale = cubes[i].transform.localScale;
previousScale.y = Mathf.Lerp (previousScale.y, spectrum[i] * 40, Time.deltaTime * 30);
cubes[i].transform.localScale = previousScale;
}
}
}
Comment
Answer by UnityCoach · Apr 10, 2017 at 01:58 PM
This is a typo. When you express a for loop, you separate every loop statements with a semicolon :
for (int i = 0; i < numberofObjects; i++) {