一秒内,按下S D U(下 右 拳)放技能。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//下 右 拳
public class XiaYouQuan : MonoBehaviour
{
//释放技能
private KeyCode[] skill = { KeyCode.S, KeyCode.D, KeyCode.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();
}
}
}
}