您的位置:首页 > 移动开发 > Unity3D

unity3d移动及键鼠状态

2017-06-08 15:21 162 查看
gameObject的transform属性可以进行位置、旋转、大小的设置

位置:position,Translate(),位置的移动

旋转:rotate

大小:localScale

Vector3内置:up、down、left、right、forward、back、zero。

鼠标判断:

Input.GetMouseButtonDown(0):只要保持按下就返回true

GetMouseButtonUp(0):只要抬起就返回true

GetMouseButton(0):只要保持按下就返回true

其中,括号内参数有0,1,2

0为左键,1为右键,2为鼠标滚轮

滚轮判断:

Input.GetAxis("Mouse ScrollWheel"):接收轴的值

0为不动,大于0表示向前,小于0表示后退

鼠标滑动值:

Input.GetAxis("Mouse X")或Input.GetAxis("Mouse Y")

鼠标在平面上左右动是X,上下动是Y

往右动是正,往左动是负

键盘判断:

Input.GetKeyDown(keyCode.Space)

Input.GetKeyUp(KeyCode.LeftArrow)

Input.GetKey(KeyCode.A),只要按住一直返回true

旋转:

transform.Rotate (new Vector3(1,0,0)):绕X轴旋转

transform.Rotate (new Vector3(0,1,0)):绕Y轴旋转

transform.Rotate (new Vector3(0,0,1)):绕Z轴旋转
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: