private int index;
public int requiredIndex; // 所需按下按钮的顺序
public GameObject[] buttons; // 所有需要按下的特定按钮
void Start()
{
index = 0;
}
void Update()
{
// 判断该按钮是否被按下
if (Input.GetKeyDown(KeyCode.Space))
{
// 如果按对了,所按的按钮索引等于当前需要按的顺序
if (requiredIndex == index)
{
index++;
// 如果所有按钮都被按下了,则过关
if (index == buttons.Length)
{
Debug.Log("You win!");
}
}
// 否则就失败,重新开始
else
{
Restart();
}
}
}
void Restart()
{
index = 0;
// 重新开始时将所有按钮的状态重置
foreach (GameObject button in buttons)
{
button.GetComponent<ButtonController>().index = 0;
}
}
}