unity input 组件代码实操

xiaoxiao2021-02-28  26

Edit->Project Settings->input

所有按钮鼠标都在这里进行配置

//监听事件都是在updata里边

                  voidUpdate () {

       //Debug.Log(Input.mousePosition);//当前鼠标的位置

       //Debug.Log(Input.anyKey);//如果一个按键一直按住,那么每一个帧都会返回true否则返回false

       /*if(Input.anyKey){

           Debug.Log(Input.anyKey);

       }*/

       //检测按键按下,一旦按下就不会再在触发了

       /*if (Input.anyKeyDown) {

           Debug.Log(Input.anyKeyDown);

       }*/

       //返回本次updata输入的字符

       /*if (Input.inputString.Length>0) {

           Debug.Log(Input.inputString);

       }*/

       //重力加速度的方向,就可以根据这个方向来获得输入

       //如果没有重力加速度,那么就是(000vector3的方向

       //Debug.Log(Input.acceleration);

       //获得当前的触摸的事件个数

       /*Debug.Log(Input.touchCount);

        if(Input.touchCount>0){

           Debug.Log(Input.touches);//事件数组

       }*/

       //Debug.Log(Input.GetAxis("Horizontal"));

       //Horizontal虚拟轴  Eidt -  projectSetting --input

       /*float value = Input.GetAxis("Horizontal");

       if (value != 0) {

           Debug.Log(value);

       }*/

       //距离上一次鼠标的变化

       /*float mouseX = Input.GetAxis("Mouse X");

       float mouseY = Input.GetAxis("Mouse Y");

       Debug.Log(mouseX);

       Debug.Log(mouseY);*/

       //鼠标左键

       /*if(Input.GetButton("Firel")){

           Debug.Log("firel click");

       }*/

       //只是在鼠标按下和弹起的那一刻为真

       if(Input.GetButtonUp("Firel")){

           Debug.Log("firel up");

       }

       if (Input.GetButtonDown("Firel")){

           Debug.Log("firel down ");

       }

       //键盘上的P按键,按下不松,一直为true

       //GetKeyDown GetKeyUp只在状态改变的时候为真

       if(Input.GetKeyDown(KeyCode.P)){

           Debug.Log("key p down");

       }

       if(Input.GetKeyUp(KeyCode.P)){

           Debug.Log("key p up");

       }

       if(Input.GetKey(KeyCode.P)){

           Debug.Log("p");

       }

       //判断鼠标有没有按下int buttron(0,1,2)鼠标左键为0右键为1中键是2

       if(Input.GetMouseButtonDown(0)){

           Debug.Log("mouse left down");

       }

       if(Input.GetMouseButtonUp(0)){

           Debug.Log("mouse left up");

       }

       if(Input.GetMouseButton(0)){

           Debug.Log("mouse left all way");

       }

         }

}

转载请注明原文地址: https://www.6miu.com/read-2800027.html

最新回复(0)