using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class KeyTest : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
//鼠标的点击
//按下鼠标 0左键 1右键 2滚轮
if (Input.GetMouseButtonDown(0)){
Debug.Log("按下了鼠标左键");
}
//持续的按下鼠标做左键
if(Input.GetMouseButton(0)){
Debug.Log("持续的按下鼠标左键");
}
//抬起鼠标
if(Input.GetMouseButtonUp(0)){
Debug.Log("抬起鼠标左键");
}
//传入参数可以为自带枚举或小写字符(注:大写字符不行)
//按下键盘按键
if(Input.GetKeyDown(KeyCode.A)){
Debug.Log("按下了" + KeyCode.A + "键");
}
//持续按下键盘按键
if(Input.GetKey("a")){
Debug.Log("持续按下了" + KeyCode.A + "键");
}
//抬起键盘按键
if(Input.GetKeyUp(KeyCode.A)){
Debug.Log("抬起了" + KeyCode.A + "键");
}
}
}
Unity 鼠键操作
于 2022-11-27 15:55:08 首次发布