- Home /
unity Javascript to C# Array Conversion
Hi I am New to Unity. I got some codes of unity games in javascript. I tried to convert that into C#. But, In Array part of conversion i was confused.
var pointArray : Array;
pointArray[0]= tempInt;
pointArray[1] = tempInt;
pointArray[5] = tempFloat;
So, We can Assign both integer and float values into the pointArray.
How to convert this type of code into C#??
This is a decent question. Sorry, I cannot answer We can Assign both integer and float values into the pointArray. , but ...
Here is a link I found helpful for lists and arrays between C# and uJS : http://wiki.unity3d.com/index.php?title=Which_$$anonymous$$ind_Of_Array_Or_Collection_Should_I_Use?
and this : http://answers.unity3d.com/questions/12911/what-are-the-syntax-differences-in-c-and-javascrip.html
Happy Coding =]
@alucardj Ya. We can assign it in javascript. But in C#, you ll be declare an array as int[] arrayname = new int[sizeof Array]; So, in that how could I assign float value(tempFloat) to arrayname. ?
Answer by MarkFinn · Nov 21, 2012 at 06:28 AM
Arrays in C# are strictly single type. You can't have different elements being different types. In this case you'd just declare it as
float[] pointArray = new float[maxsize];
and save the int values as floats.
Accessing values (or setting them) is simply
float f = pointArray[3];
pointArray[27] = f;
Your answer
Follow this Question
Related Questions
Why ExecuteInEditMode Always Causes NullReferenceException Errors Even In Clamping!! 2 Answers
Checking an array variable in C# vs JavaScript 3 Answers
Multiple Cars not working 1 Answer
what's wrong with this?? 2 Answers
Toggle ON/OFF MaterialChange 0 Answers