KeyPressEventReceiver
Last updated
Last updated
Key Selection
Key
(KeyCode): The key that this script is listening for.
Settings
Listener
(ListenerType): Determines where this script should listen for key press events. Can be either Class
or Class via Singleton Instance
.
Events
OnKeyPressReceived
(UnityEvent): Event that is invoked when the specified key is pressed. The key is passed as a string.
OnKeyPress(KeyCode obj)
(void): Method that is called when a key is pressed. If the pressed key matches the specified key, OnKeyPressReceived
is invoked.
StopListening()
(void): Unsubscribes this script from key press events.
SetKey(string str)
(void): Sets the key that this script is listening for. The key is passed as a string and converted to a KeyCode.
UnsubscribeFromKeyPressEvents()
(void): Unsubscribes this script from key press events. This is called when the script is disabled or destroyed.
Start()
(void): Subscribes this script to key press events based on the Listener
setting.
OnDestroy()
(void): Unsubscribes this script from key press events when the script is destroyed.
OnDisable()
(void): Unsubscribes this script from key press events when the script is disabled.
This script should be attached to a GameObject in your scene. You can specify the key to listen for and the listener type in the Inspector. When the specified key is pressed, the OnKeyPressReceived
event will be invoked.