- Input.GetKey () 用来检测用户持续按键的事件
- Input.GetKeyDown() 用来检测用户按键按下的事件
- Input.GetKeyUp() 用来检测用户按键弹起的事件
- Input.GetMouseButton () 用来检测用户持续按键的事件
- Input.GetMouseButtonDown () 用来检测用户按键按下的事件
- Input.GetMouseButtonUp () 用来检测用户按键弹起的事件
参数 0 表示鼠标左键
参数 1 表示鼠标右键
参数 2 表示鼠标中键
using UnityEngine;
using System.Collections;
public class Test : MonoBehaviour
{
void Start()
{
}
void Update()
{
if (Input.GetKeyDown(KeyCode.W))
{
Debug.Log ("往前走");
}
if (Input.GetKeyDown(KeyCode.S))
{
Debug.Log("往后退");
}
if (Input.GetKeyUp (KeyCode.Alpha1))
{
Debug.Log("弹起了1键");
}
if (Input.GetKey(KeyCode.A))
{
Debug.Log("往左转");
}
if (Input.GetMouseButtonDown(0))
{
Debug.Log("按下了鼠标左键");
}
if (Input.GetMouseButtonDown(1))
{
Debug.Log("按下了鼠标右键");
}
if (Input.GetMouseButtonDown(2))
{
Debug.Log("按下了鼠标中键");
}
if (Input.GetMouseButtonUp(0))
{
Debug.Log("弹起了鼠标左键");
}
if (Input.GetMouseButtonUp(1))
{
Debug.Log("弹起了鼠标右键");
}
if (Input.GetMouseButtonUp(2))
{
Debug.Log("弹起了鼠标中键");
}
if (Input.GetMouseButtonUp(0))
{
Debug.Log("持续按鼠标左键");
}
}
}
