I have different scripts on whcih I have to check all the time if escape button then bla bla. It’s not that bad but I think it could be handled much more easily with events. I am thinking of creating, I already have InputHandler class, full of static methods so I thought I could make a static or non static event(if non static, to use singleton) and eventually attach all the methods from all the different scripts that depend on the escape button to this event.(note if you ask why just not check in every script for escape button, simply because most of them don’t have update functions, nor coroutines to wait for smth to happen)
My question is is there a better, easier alternative I can use to achieve same thing with unity?
P.S If my approach is the best, should I use singleton or just static event?
Personally I would avoid static events and static things as much as possible, static is useful sometimes but if it is not handled correctly can cause many problems and hidden dependencies that can be hard to spot, also they make Unit Testing hard, very hard.
(You can find many resources on why static and Singletons are bad).
I would create an empty GameObject with a script that checks for the Escape key to be pressed and if it is pressed it will fire an Event.
Then in other scripts retrieve that empty GameObject, get the script by using GetComponent from the empty object reference and subscribe to its event handler for the Escape key.
Or you can do the other way around: you can Tag the GameObjects that should receive the Escape Key event, get them from the script that checks for the Escape key (attached to an empty GameObject) with FindGameObjectsWithTag.
Once you have found them, with GetComponent for each of the event receiver found, get the script with the correct method that should handle the event and invoke it when the escape key is pressed. (extra points if you make each script implement an interface with the method that should be executed).
Rember to do this components search at script startup and cache the results to increase performance.