button cooldown to prevent spamming

This commit is contained in:
2022-11-29 08:45:00 +01:00
parent 450c16c94f
commit 3adf743c4c
9 changed files with 1462 additions and 1 deletions

View File

@@ -18,6 +18,8 @@ namespace EscapeRoomEngine.Desert.Runtime.Puzzle_B
public class PuzzleB : StatePuzzle
{
[SerializeField] [Min(0)]
private float buttonCooldown = 1;
[ValidateInput("CorrectRotatorCount")]
public List<Rotator> rotators;
[InfoBox("Every button action will toggle the states at the given indices between 0 and 90 degrees.")]
@@ -29,6 +31,7 @@ namespace EscapeRoomEngine.Desert.Runtime.Puzzle_B
private Crystal crystal;
private DynamicColor _puzzleColor, _solvedColor;
private float _previousPress = -1;
protected override void Awake()
{
@@ -69,9 +72,11 @@ namespace EscapeRoomEngine.Desert.Runtime.Puzzle_B
{
buttonAction.button.ButtonEvent += (_, type) =>
{
if (type == ButtonEventType.Pressed)
if (type == ButtonEventType.Pressed && _previousPress + buttonCooldown <= Time.time)
{
Switch(buttonAction);
_previousPress = Time.time;
}
};
}