如下:
void Update()
{
//識別鍵盤輸入
//鍵盤A鍵按住
//第一種方式 "a" 必須是小寫字母
if (Input.GetKey("a"))
{
Debug.Log("a");
}
//第二種方式 KeyCode的枚舉類型
if (Input.GetKey(KeyCode.A))
{
Debug.Log("A");
}
//鍵盤A按下瞬間
if (Input.GetKeyDown("a"))
{
Debug.Log("a");
}
if (Input.GetKeyDown(KeyCode.A))
{
Debug.Log("A");
}
//鍵盤A抬起瞬間
if (Input.GetKeyUp("a"))
{
}
if (Input.GetKeyUp(KeyCode.A))
{
}
//識別鼠標輸入
//鼠標左鍵按住
//int 0 (右鍵1 中鍵2)
if (Input.GetMouseButton(0))
{
}
//鼠標左鍵按下瞬間
if (Input.GetMouseButtonDown(0))
{
}
//鼠標左鍵抬起瞬間
if (Input.GetMouseButtonUp(0))
{
}
}