Unity Script與C#的差異
兩者之間除了語法上的差異外,在某些用法上也有不小的差距,如下表所示。
Unity Script | C# | |
---|---|---|
function override | can override all function | need to tag virtual before function |
value type assignment | transform.position.z += 1; | transform.Translate (Vector3.forward * Time.deltaTime); |
call static method | can use instance | can not use instance (must use classname) |
switch case | fall through | goto case 'xxx'; |
type auto-transformation | if(GameObject.Find("foo")) | if(GameObject.Find("foo") != null) |
== | everything can compare to everything | must be the same type or have extending relation |
suffix | var q : float = 0; | float q = 0f; |
list literal | var arr : float[] = [1,2,3]; | float[] arr = new float[] {1f, 2f, 3f}; |
new | with or without all accept | must with it |
arr.length | lowercase 'l' | uppercase 'L' |
parse | parseInt | Int.Parse |
local variable | x | o |
event & delegate | x | o |
ref & out | x | o |
struct | x | o |
Ref: unity-dossier