- Home /
C# Array Question
I can't get this little snipped of code to work so I obviously screwed up something pretty simple. This is the line.
float[] levelmult = [5.0, 30.0, 80.0, 130.0, 200.0, 320.0];
Thanks is advance.
You need a lower case "f" after each float with a decimal.
You need to define the array as a new float array in awake or start
float[] levelmult; void Awake() { levelmult = new float[] { 5.0f, 30.0f, 80.0f, 130.0f, 200.0f, 320.0f }; //Don't forget the semicolon after your closing bracket. }
Answer by MartinCA · Jul 30, 2013 at 12:04 AM
As clunk mentioned, you need to add the f suffix to numbers with decimal point, otherwise by default they are interpreted as double percision.
Arrays in C# are not primitives and have to be explicitly initialized with the new keyword. Also, initial array data needs to be wrapped in curly braces:
float[] levelmult;
void Awake() { levelmult = new float[]{ 1.0f, 2.0f, 3.0f }; }
Looks like OP isn't going to respond, and this looks like a good solution, nicely explained. I'll go ahead and accept this since it will work.
Answer by perchik · Jul 29, 2013 at 11:55 PM
Try the first link, read the page. We're not super smart or something, we just know how to use the tools at hand.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Renderer on object disabled after level reload 1 Answer
Convert from JS to C# 1 Answer