unity3d中javasciprt脚本参考

1.关键字(keyword)

 as boolean break byte case catch char class continue default
double else enum extends finally float for function if import
in instanceof int long new null private protected public return

short static super switch this throw try typeof var while

2.变量

变量可以是public或者private的,public变量可以被外界访问,private变量只能在当前脚本中直接访问;如果不加修饰则默认是public的

利用@HideInInspector指令可以不让public变量

如:

@HideInInspector

var someVar : int = 0;

内置的变量类型如下表:

Type Description Example
sbyte 8-bit signed integer. var n : sbyte = -2;
short 16-bit signed integer. var n : short = -2;
int 32-bit signed integer. var n : int = 2;
long 64-bit signed integer. var n : long = 2;
byte 8-bit unsigned integer. var n : byte = 2;
ushort 16-bit unsigned integer. var n : ushort = 2;
uint 32-bit unsigned integer. var n : uint = 2;
ulong 64-bit unsigned integer. var n : ulong = 2;
float Single-precision floating point value. var f : float = 2.0;
double Double-precision floating point value. var f : double = 2.0;
boolean Represents a true / false value. var b : boolean = true;
char A unicode character. var c : char = "c"[0];
String Represents text as a series of Unicode characters. var s : String = "Hello, world";

3.控制语句

if(xxx){}

if(xxx){} else{}

if(xxx){} else if(yyy) else{}


for(var i : int = 0; i < 100; i++)

{

// do something
}


while(xxx)

{
}


do{

}while(xxx);


4.异常

try

{

//do something

}catch( e : System.Exception )

{

//except
}


你可能感兴趣的:(unity3d,Unity3D)