Transform基本移动函数:
transform.Translate(Vector3.forward *TranslateSpeed);
transform.Translate(xSpeed,0,zSpeed);
transform.position = Vector3(xPostion,0,zPostion);
1.输入指定按键:
if(Input.GetKey ("up")) print("Up!"); if(Input.GetKey(KeyCode.W);) print("W!");
2.鼠标控制
//按下鼠标左键(0对应左键 , 1对应右键 , 2对应中键) if(Input.GetMouseButton(0)) print("Mouse Down!");
Input.GetAxis("Mouse X");//鼠标横向增量(横向移动)
Input.GetAxis("Mouse Y");//鼠标纵向增量(纵向移动)
3.获取轴:
//水平轴/垂直轴 (控制器和键盘输入时此值范围在-1到1之间) Input.GetAxis("Horizontal");//横向 Input.GetAxis ("Vertical");//纵向
物体旋转
transform.Rotate(new Vector3(x,y,0));
物体缩放:
transform.localScale += new Vector3(x, 0, z);