蓝鸥Unity入门Input类学习笔记

来源:互联网 发布:霍华德新秀体测数据 编辑:程序博客网 时间:2024/05/01 07:11

unity3D-游戏/AR/VR在线学习 蓝鸥Unity入门Input类学习笔记

相关文章

蓝鸥Unity入门脚本组件学习笔记
蓝鸥Unity入门脚本生命周期学习笔记

Input

Input获取键盘事件

Input获取鼠标事件

using UnityEngine;using System.Collections;public class Test : MonoBehaviour {    void Start () {        }    //获取用户事件需要使用Input类    void Update () {        //每帧都需要监听用户事件        //在当前这一帧中,如果用户按下W就会返回true,否则返回false            if (Input.GetKeyDown (KeyCode.W)) {            print ("往前走");        }        //Input.GetKeyDown()方法用来检测按键按下的事件            if (Input.GetKeyDown (KeyCode.S)) {            //print只能在MonoBehaviour的子类中使用,其他情况下只能使用Debug.Log()打印            Debug.Log ("往后退");        }        //Input.GetKeyUp()方法用来检测按键弹起的事件        if(Input.GetKeyUp(KeyCode.Alpha1)){            print ("弹起了1键");        }        //Input.GetKey()方法用来检测持续按键的事件        if(Input.GetKey(KeyCode.F)){            print ("按下了F键");        }        //Input.GetMouseButtonDown()方法用来检测鼠标按键按下的事件        //参数0表示鼠标左键        //参数1表示鼠标右键        //参数2表示鼠标中键        if(Input.GetMouseButtonDown(0)){            print ("按下鼠标左键");        }        //Input.GetMouseButtonUp()方法用来检测鼠标按键弹起的事件        if(Input.GetMouseButtonUp(0)){            print ("弹起了鼠标左键");        }        //Input.GetMouseButton()方法用来检测鼠标持续按下的事件        if(Input.GetMouseButton(0)){            print ("持续按下鼠标左键");        }        }}

0 0