I would like to add a time delay to certain functions the player can execute by pressing a button on the keyboard, mouse etc, since that way they can be executed as fast as the player can click or press.
For example functions like switching weapons, toggling iron sight aiming mode etc.
Its not a functional problem, but more a cosmetic one, since it does not look and feel very realistic, if you can execute certain tasks in no time.
Ok for weapons this is usually solved with a state machine, but there are other functions, like the aiming function I added that lets you switch to iron sight aiming mode by pressing right mouse button:
https://github.com/Duion/Uebergame/blob ... nd.cs#L783
This is based on some resource from the old forum, it quickly exchanges the weapon images and adds zoom to simulate aiming mode, the problem is just, that it can be pressed infinitely fast and therefore can look ugly and unrealistic if the player presses the right mouse button very fast.
It is not part of the state machine, since that would require source code changes by adding that functionality to the weapon class, but I don't have the time and skill to do that, so has anyone an idea what I could use as a workaround?
Scheduling does not work, since it jut delays the execution, but does not limit the input speed.
Only idea I have is to lock it and automatically unlock after a certain amount of time with a schedule, but this system is prone to errors and I don't know if it works well with very small delays like 50-300ms.