I know it's kind of a basic question, but it doesn't seem there is a clear answere around. When you declare an array as a class field, variable size-determined at the run time is not allowed,
public class MyClass : MonoBehaviour{
int size = 6;
float[] f = new float[size]; //not allowed
// Start is called before the first frame update
void Start()
{
//some code
}
}
while declaring it the same way but as a local variable inside a function e.g. Start is perfectly fine:
public class MyClass : MonoBehaviour{
void Start()
{
int size = 6;
float[] f = new float[size];
//some code
}
}
Is this related to the scope of the variables? Or with the where the memory allocation takes place stack, heap etc? Thank you in advance