-1
我正在做游戏,您尝试避开障碍物。我为慢动作制作了一把钥匙。当玩家按下它时,它会保持活动状态3秒,然后比我想禁用该键6秒以防止他再次按下它,我不知道该怎么做。我想禁用X秒的密钥
我正在做游戏,您尝试避开障碍物。我为慢动作制作了一把钥匙。当玩家按下它时,它会保持活动状态3秒,然后比我想禁用该键6秒以防止他再次按下它,我不知道该怎么做。我想禁用X秒的密钥
使用Timer类。
public static void Main()
{
myButton.Enabled = false;
System.Timers.Timer timer = new System.Timers.Timer();
timer.Elapsed +=new ElapsedEventHandler(OnTimedEvent);
timer.Interval = 5000; // Specify the timespan
timer.Enabled = true;
}
private static void OnTimedEvent(object source, ElapsedEventArgs e)
{
myButton.Enabled = true;
}
您可以添加某些处理器的Elapsed
事件,并指定一些时间跨度(以millisecnonds)后,每个处理程序被调用。
使用该定时器:
System.Timers.Timer t = new System.Timers.Timer();
t.Elapsed+=new ElapsedEventHandler(OnTimedEvent);
t.Interval=3000;
t.Enabled=true;
aButton.Enabled = false;
private static void OnTimedEvent(object source, ElapsedEventArgs e)
{
aButton.Enabled = true;
(source as Timer).Enabled = false;
}
请分享您的代码 – natanelg97
您是否尝试过任何东西? – Karolis
你知道如何让游戏变得流畅,但不能禁用按钮...你通过问这个问题开始你的项目我感觉... – EpicKip