⌨️
Thock
Get Thock
  • About
    • ⌨️Description
    • 🚀Quick Start
    • ™️Third-Party information
    • Sample Scenes
      • Example_ScreenTypewriter-and-Soundpacks
      • Example_Type
      • Example_StringEvents
  • Documentation
    • Thock
    • Convert JSON to Soundpack
      • ConvertJsonToSoundpack
    • Utilities
      • StringEventListener
        • StringEventListener Component Tutorial
      • KeyPressEventReceiver
      • KeyPressEventSender
    • Scriptable-Objects
      • SoundPackSO
      • IntToKeyCodeTable
      • StereoAudioMapping
      • StringToKeycodeTable
    • Types
      • SoundMap
Powered by GitBook
On this page
  • Why Use StringEventListener?
  • How to Use StringEventListener?
  1. Documentation
  2. Utilities
  3. StringEventListener

StringEventListener Component Tutorial

Why Use StringEventListener?

The StringEventListener component is useful in scenarios where you want to trigger an event based on a specific sequence of keypresses. For example, you might want to trigger a special ability in a game when the player enters a specific cheat code. The StringEventListener makes it easy to implement this functionality.

How to Use StringEventListener?

Here's a step-by-step guide on how to use the StringEventListener component:

  1. Add the Component: First, add the StringEventListener component to the GameObject where you want to listen for the keypress sequence. You can do this by selecting the GameObject in the Unity editor, then clicking on Add Component and searching for Thock/StringEventListener.

  2. Set the Listener Type: The ListenerType property determines where the component should listen for keypress events. You can choose from three options: KeyPressEventSenderClass, ThockClass, and PublicMethodOnly. Note that the component listens to Thock events, not actual keypresses, so a Thock component in the scene is required.

  3. Set the Event Trigger String: The eventTriggerString property is the sequence of keypresses that will trigger the event. Enter the sequence you want to listen for in this property. Note that the sequence should be in uppercase letters as it's coming from keycodes.

  4. Set the Timeout: The timeOut property is the time window in which the keypress sequence must be entered to trigger the event. If the sequence is not entered within this time window, the component will reset and start listening for the sequence again.

  5. Set the Event: Finally, you need to set the event that will be triggered when the keypress sequence is entered. You can do this by adding a new event to the onEventTriggerString UnityEvent.

PreviousStringEventListenerNextKeyPressEventReceiver

Last updated 1 year ago