Skip to content

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
  1. Create an empty GameObject, for example Button.
  2. Add Component > search DigitalInputEvent.
  3. In Action Reference, pick the D2 action from your generated Input Actions asset.

A quick test that needs no code: show and hide an object.

  1. Add a Cube to the scene.
  2. Under Digital ON, click +, drag the Cube in and choose GameObject > SetActive (bool). Tick the checkbox.
  3. 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.

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.

Switch an LED from Unity with DigitalOutputHelper →