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 eitherSendToThockGameObjectorSendToThockInstance.
Thock Reference
Reference(Thock): The Thock instance that this script will send key press events to. This is only used ifsenderis set toSendToThockGameObject.
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 theOnKeyPressevent 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, thePressKeymethod is called.SendKeyPressToThock(KeyCode key)(void): Sends a key press event to the specified Thock instance.
Unity Methods
Update()(void): IfListenInUpdateis true, theCheckKeymethod is called in this method.OnValidate()(void): SetsisSenderThockGameObjectbased on thesendersetting.
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