In this recipe, you created a C# script class, called SpectrumCubes. You created a GameObject with an AudioSource component and an instance of your scripted class. All the work is done by the methods of the SpectrumCubes C# script class. Here is an explanation of each of these methods:
- The void Awake() method: This method caches references to the sibling AudioSource component and then invokes the CreateCubes() method.
- The void CreateCubes() method: This method loops for the number of samples (the default is 512) to create a 3D Cube GameObject, in a row along the x axis. Each cube is created with the name of SampleCube<i> (where "i" is from 0 to 511) and then parented to the visualizer GameObject (since the scripted method is running in this GameObject). Then, each cube has the color of its renderer set to the value of the public displayColor parameter. The cube is then positioned on the x axis according to the...