Game Development Reference
In-Depth Information
Variable with Dynamic Type
Resolution
Only in JavaScript, variables can have an unspecified type. This only occurs if you don't assign
a value or specify a type while declaring the variable.
JavaScript: The type speciicaion is not necessary.
var playerLife : int; // statically typed (because type specified)
var playerLife = 2; // statically typed (because type is inferred
from value
assigned)
var playerLife; // dynamically typed (because neither a type or value
is specified)
The dynamically typed variables will cause slower performance, and you can run into casing
problems. You can use #pragma strict , including it at the top of a script, to tell Unity to
disable the dynamic typing in the script and report compile errors when this is a dynamic
type in the script.
Multi-dimensional array declaration
JavaScript:
var myArray = new int[8,8]; // 8x8 2d int array
C#:
int[,] myArray = new int[8,8]; // 8x8 2d int array
Character literals not supported
Unity's JavaScript seems to be missing the syntax to declare character literals. This means
you need to get them implicitly by referencing a character index from a string.
JavaScript:
var myChar = "a"[0]; // implicitly retrieves the first character
of the string "a"
C#:
char myChar = 'a'; // character 'a'
 
Search WWH ::




Custom Search