O'Reilly logo

Unity 3 Game Development HOTSHOT by Jate Wittayabundit

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 specification is not necessary.

var playerLife : int;  // statically typed (because type specified)
var playerLife = 2;  // statically typed (because type is inferred from valueassigned)
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 casting 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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required