获取轴向与键

来源:互联网 发布:扒一扒陈娅安 知乎 编辑:程序博客网 时间:2024/04/21 00:08

获取轴向

float speed = 10.0f;

float speed_w = 100.0f;

void Update()

{

    float translion = Input.GetAxis("Vertical") * speed;

    //获取鼠标的垂直轴向,返回值是float类型

    //局部变量,只能在当前函数里面运用

    float ratation = Input.GetAxis("Horizontal") * speed_w;

    transform.Translate(0,0,translion);//让物体移动,调用垂直轴向

    transfrom.Rotate(0,rotation,0);//让物体旋转,调用水平轴向

    if(Input.GetAxis("Mouse ScrollWheel") != 0)//获取鼠标滚轮,非0(静止)状态

    {

        print("滚轮在动");

    }

}

获取键

if(Input.GetKey(KeyCode.W))//按下时实时返回为true

if(Input.GetKeyDown(KeyCode.S))//按下的第一帧返回为true

if(Input.GetKeyUp(KeyCode.S))//抬起的第一帧返回为true

if(Input.GetMouseButtonDown(2))//获取鼠标中键,左键为0,右键为1

0 0
原创粉丝点击