Hello all!
I try to port a game to iPhone.
(It’s a little golf game, my first in Unity! ebark.se)
Where did I find info about the difference between dynamic typing, #pragma strict, statically typing the variables… and so on…
Somewhere in the docs? Or shall I buy a book? Where did you guys begin…?
Grateful for all help…
There is no specific docs for it. It’s simple like, use type all time that’s it :).
var t1 : float;
var t2 : String;
var t3 : Vector3 = Vector3.up;
etc.
Actually, you only need to explicitly specify the type when it can’t be inferred at compile time. Thus
var t3 = Vector3.up;
will still work fine, as the compiler already knows that Vector3.up is a Vector3. The first two examples do need the type, as there is no assignment.
Other places where you need to be explicit about types is in function arguments and when assigning values from functions that can return different types.
function OnCollisionEnter( c : Collision ) { ... }
var i : MyScript = GetComponent(MyScript);
The difference between the two are:
Strongly Typed:
You in most cases qualify a variable definition with the type of variable it is going to be.
(C#)
string playerName = string.empty;
int playerHitPoints = 10;
float playerPosX, playerPosY, playerPosZ;
on the flip side:
when typing is not strong(this is for the most part) in a language, just defining a var and the value first being passed into the variable will define it. Just as was stated with:
(JS)
var t3= vector3.up;
That’s actually not the case. In Javascript (in Unity), “var t3 = Vector3.up” is in fact strongly typed. It’s using type inference; there’s no difference between that and “var t3 : Vector3 = Vector3.up”.
On the other hand,
function Add (a, b) {
return a + b;
}
is dynamically typed, since there’s no way to infer what a or b should be at compile time, so Unity figures it out on the fly, which is slower. To avoid that, you could do
function Add (a : int, b : int) {
return a + b;
}
Of course, you can see that the advantage of dynamic typing with this simple example is that you only need one function, whereas you’d need to write a number of functions to cover the various possibilities otherwise.
–Eric
Hi
The game is on my iPhone!
Your info helpt me.
Thax!