Question about Array indexing
I'm working on a tutorial about fractals (C#) from catlikecoding.com, and am having an issue understanding a concept. I might be missing some code for context, but basically this is creating a mesh, and the materials are being added is materials !=null See Below:
public Mesh mesh;
public Material material;
public int maxDepth;
public float childScale;
int depth;
Material[] materials;
void InitializeMaterials(){
**materials = new Material[maxDepth + 1];**
for (int i = 0; i <= maxDepth; i++) {
**float t = i / (maxDepth - 1f);**
**t *= t;**
materials [i] = new Material (material);
materials [i].color = Color.Lerp (Color.white, Color.red, t);
}
materials [maxDepth].color = Color.magenta;
}
The starred are what I'm not understanding. How is the [maxDepth+1] working? The number doesn't matter (entering +10 does the same job). It is basically instantiating a range of colors as new gameObjects are added to the scene. Is it because it is being indexed maxDepth + 1 = 5, maxDepth +1 = 6, etc?
And also, I'm not quite sure how the time function is working. Is the equation saying t = maxDepth + 1/maxDepth -1?
Sorry for the long winded question. I'm going into my second quarter of classes and we haven't started C# yet so I'm still pretty new at this.
Your answer
![](https://koobas.hobune.stream/wayback/20220612124450im_/https://answers.unity.com/themes/thub/images/avi.jpg)