button cooldown to prevent spamming
This commit is contained in:
@@ -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;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user