一、Transform
1、位置移动(向X轴移动10)
属性
transform.position = new Vector3(10, 0, 0);
transform.position = Vector3.right * 10;
方法
transform.Translate(new Vector3(10, 0, 0));
transform.Translate(Vector3.right * 10);
transform.translate(10, 0, 0);
2、旋转角度(沿Y轴旋转45度)
属性
transform.rotation = Quaternion.Euler(0, 45, 0);
方法
transform.Rotate(new Vector3(0, 45, 0));
3.缩放(放大至2倍)
属性
transform.localScale = new Vector3(2, 2, 2);
方法
transform.localScale = Vector3.one * 2;
二、Vector3
具有方向和大小的量,用一条线段表示
三、GameObject
GameObject和gameObject的区别
GameObject是游戏对象类的基类
gameObject是脚本挂载的对象
四、Time
Time.time:表示从游戏开始到现在的时间,会随着游戏的暂停而停止计算。
Time.deltaTime:表示从上一帧到当前帧的时间,以秒为单位。
Time.timeScale:时间缩放,默认值为1,若设置<1,表示时间减慢,若设置>1,表示时间加快
五、克隆游戏对象
在预设体cube的位置克隆游戏对象
GameObject go1=Instantiate(cube);
在指定位置克隆游戏对象
GameObject go2 =Instantiate(cube,new Vector3(0,0,5),Quaternion.identity);Quaternion.identity 游戏对象不旋转
六、销毁游戏对象
Destroy(go1); //直接销毁对象go1
Destroy(go2,3); //停3秒后销毁对象go2
七、查找游戏对象
通过名称来查找游戏对象
GameObject cube1=GameObject.Find("Player");
通过标签名称查找游戏对象
GameObject cube2=GameObject.FindWithTag("Player");
八、添加,获取组件
把Move这个脚本加到cube这个游戏对象上
cube.AddComponent("Move");
获取脚本组件Move
Move m=cube.GetComponent<Move>();
九、Random
float a=Random.value; //返回0.0(包括)到1.0(包括)之间的数。
int b=Random.Range(0,100) ; //包括最小但不包括最大
float c=Random.Range(0.0f,5.5f); //包括最大和最小
十、Input
1、鼠标事件(作为if语句的条件)
GetMouseButton(0):按下鼠标左键不动,程序会一直运行,松开左键程序停止运行。
GetMouseButton(2):按下鼠标中键不动,程序会一直运行,松开中键程序停止运行。
GetMouseButton(1):按下鼠标右键不动,程序会一直运行,松开右键程序停止运行。
GetMouseButtonDown(0):按下鼠标左键时,程序运行一次
GetMouseButtonDown(1):按下鼠标右键时,程序运行一次
GetMouseButtonUp(2):按下鼠标中键时,程序不运行,松开中键时,程序运行一次。
2、键盘事件
GetKey 当通过名称指定的按键被用户按住时返回true
GetKeyDown 当用户按下指定名称的按键时的那一帧返回true。
GetKeyUp 在用户释放给定名字的按键的那一帧返回true。
GetAxis("Horizontal")和GetAxis("Vertical") 水平轴和垂直轴