KeyPressEventSender
KeyPressEventSender.cs is a script that detects key press events and sends them to a specified receiver. It can send these events to a specific Thock instance or invoke a UnityEvent.
Key Selection
- Key(KeyCode): The key that this script is listening for.
Settings
- ListenInUpdate(bool): If true, the script will check for key presses in the Update method.
- isSenderThockGameObject(bool): If true, the script will send key press events to a specific Thock instance.
- sender(SenderType): Determines where this script should send key press events. Can be either- SendToThockGameObjector- SendToThockInstance.
Thock Reference
- Reference(Thock): The Thock instance that this script will send key press events to. This is only used if- senderis set to- SendToThockGameObject.
Events
- OnKeyPress(UnityEvent): Event that is invoked when the specified key is pressed.
- OnKeyPressAction(Action): Static event that is invoked when the specified key is pressed.
Public Methods
- PressKey()(void): Invokes the- OnKeyPressevent and sends a key press event to the specified Thock instance.
- 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.
Private Methods
- CheckKey()(void): Checks if the specified key is pressed. If it is, the- PressKeymethod is called.
- SendKeyPressToThock(KeyCode key)(void): Sends a key press event to the specified Thock instance.
Unity Methods
- Update()(void): If- ListenInUpdateis true, the- CheckKeymethod is called in this method.
- OnValidate()(void): Sets- isSenderThockGameObjectbased on the- sendersetting.
This script should be attached to a GameObject in your scene. You can specify the key to listen for and the sender type in the Inspector. When the specified key is pressed, the OnKeyPress event will be invoked and a key press event will be sent to the specified Thock instance.
Last updated