4 – DigitalInputEvent component
DigitalInputEvent listens to one button Input Action and fires two events:
- Digital ON when the button is pressed
- Digital OFF when it’s released
Before you start
Section titled “Before you start”- A push button between D2 and GND (see Wire the demo circuit).
- A profile with D2 set to Digital In, its Input Actions, and the SerialInputBridge prefab in the scene (see Install, set up and test).
1. Add the component
Section titled “1. Add the component”- Create an empty GameObject, for example
Button. - Add Component > search DigitalInputEvent.
- In Action Reference, pick the D2 action from your generated Input Actions asset.
2. Hook up the events
Section titled “2. Hook up the events”A quick test that needs no code: show and hide an object.
- Add a Cube to the scene.
- Under Digital ON, click +, drag the Cube in and choose GameObject > SetActive (bool). Tick the checkbox.
- Under Digital OFF, do the same and leave the checkbox unticked.
Press Play. The cube shows while you hold the button and hides when you let go.
Toggling instead of holding
Section titled “Toggling instead of holding”Point Digital ON at a method that flips something, and leave Digital OFF empty. Each press then toggles. For example, an LED on the board: see DigitalOutputHelper and its Toggle method.