is there equivalent in js of c++ const definition and array initialize?
in specific,
1.
if i want to define a const like
var MAX_NUM = 6;
is there a way to prevent it from being modified?
furthermore, can i prevent it from being showed in the inspector window?
2.
how to initialize a class array with const data? like this in c++:
class foo
{
int a;
int b;
};
foo myArray[10] = {
{0, 0},
{1, 1},
...
};
I don’t think this is possible in Unity Script (Javascript constants would have ‘var’ replaced by ‘const’, but this does not compile in Unity). If you really need constants, you will have to switch to using C#. Constants are automatically hidden in the inspector (in fact cannot be shown), but if you wish to hide a public variable, you can use the HideInInspector attribute:
Initializing base type arrays is possible, but class type arrays is not. C# does support custom class initializers but not in the mono-version used by Unity.