I'm a newbie programmer and learn at the moment c# and Unity3d.
I got a problem, as i tried to initialize an array of public float variables.
[Range (0,1)]
public float appleProbability = 0.4f ;
[Range (0,1)]
public float fishProbability = 0.2f ;
[Range (0,1)]
public float cheeseProbability = 0.10f ;
[Range (0,1)]
public float poopProbability = 0.14f ;
[Range (0,1)]
public float bombProbability = 0.14f ;
[Range (0,1)]
public float starProbability = 0.02f ;
private float[] probs = new float[] {appleProbability, fishProbability, cheeseProbability, poopProbability, bombProbability, starProbability};
(The [Range (0,1)] should make a slider in the inspector of the script in unity, so you can manipulate the public variable between 0 and 1 with the slider.)
I get the error: "A field initializer cannot reference the non-static field, method or property 'GameManager.appleProbability'." (the same for the other variables)
I tried this code for a test:
public int blub = 1;
public int hub = 2;
private int[] bla = new int[3];
bla[0] = blub;
but I get the error: "Array size cannot be specified in a variable declaration (try initializing with a 'new' expression)."
Strange thing is, that the first error dissapears, when I get the second error, also I haven't changed the code from the first error.
I've read this question all possible c# array initialization syntaxes but it doesn't help.
I'm feeling a little bit stupid, but I don't get the error :/