键鼠输入
Void Update()
{
//键鼠输入
//任意按键按下
if(Input.anyKey)
{
按下会一直调用
}
if(Input.anyKeyDown)
{
按下一次调用一次
}
//监听按键
if(Input.GetKeyDown(KeyCode.Space))
{
按下空格监听一次
}
if(Input.GetKey(KeyCode.Space))
{
按下空格一直监听
}
if(Input.GetKeyUp(KeyCode.Space))
{
抬起空格监听一次
}
//鼠标 0:左键 1:右键 2:中键
if(Input.GetMouseButtonDown(0))
{
点击一次监听一次
}
//通过同时按下多个键实现一个效果
public class InputTest:MonoBehaviour
{
//释放技能
private KeyCode[] sKill={KeyCode.S,KeyCode.D,KecCode.U};
//按键时间
Private float sKillTime=1;
//计时器
Private float timer=0;
//按的键
Private List<KeyCode> InputBuff;
Void Start()
{
InputBuff=new List<KeyCode>();
}
Void Update()
{
timer+=Time.deltaTime;
If(Input.GetKeyDown(KeyCode.S))
{
Debug.Log(“开始输入”);
timer=0;
//清空按键
InputBuff.Clear();
//添加按键
InPutBuff.Add(KeyCode.S);
}
If(Input.GetKeyDown(KeyCode.D))
{
InputBuff.Add(KeyCode.D);
}
If(Input.GetKeyDown(KeyCode.U))
{
InputBuff.Add(KeyCode.U));
}
If(timer<SkillTime&&InputBuff.Count>=Skill.Length)
{
Bool isSkill=false;
For(int i=0;i<skill.Length;i++)
{
If(InputBuff[i]==skill[i])
{
isSkill=true;
}else
{
isSkill=false;
Break;
}
}
}
If(isSkill)
{
//放出技能
Debug.Log(“”);
Timer=0;
InputBuff.Clear();
}
}
}