- Home /
Help Unity Script to C#!!
In my project I had written scripts in js but have come to the realization that C# is the better route to go as I am now having to written Scripts in C# The one problem I have is converting `static var materials : Material[]; materials = new Material[5];` into C#. The reason I want this is because I have a set of Materials, lets say Brick, Stone, and Copper. Whenever I certain button is pressed it would set var materialCt to a number that I have designated for each Material and then set materials[] to the correct material
ex. if(brickButton){ materialCt = 0; materials[0] = materialBrick // materialBrick being of type Material }
Would I have to do so using `List materials = new List()`? or is there a better way? Thank You
Answer by Sundar · Aug 24, 2012 at 05:29 PM
Its your choice you can still use array but if you want to use list
using System.Collections.Generic;
class yourClass : Monobehaviour {
List<Material> materials = new List<Material>(5);
int materialCt = 0;
public Material materialBrick;
yourReturnVariable yourFunction{
if( brickButton ){
materials[materialCt] = materialBrick;
}
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613080123im_/https://answers.unity.com/themes/thub/images/avi.jpg)