UE4: The button is pressed to trigger a sound event, and the sound stops when the position is left

UE4: The button is pressed to trigger a sound event, and the sound stops when the position is left

basic needs

Scene design
In the trigger box of the box body, press the [Down] key to start playing the sound. The sound stops when you leave the area.


Things to pay attention to :

  1. The situation of pressing multiple times in a row should be handled as: only one press, and no response for subsequent times.
  2. The sound stops when you leave the area. Pressing the down key in other areas does not trigger sound events.

Scene design

Select the box body trigger and place it in a suitable position.

logical structure

Here we choose to solve the problem using two Boolean variables.
Check the information, and realize it with enable input and diable input.

Reference:
Playing and stopping UE4 music – based on the blueprint
UE4 (Unreal 4) basics: Introduction to blueprint – opening and closing the door (2) keyboard control door

Two Boolean variables:
inPosition: The default is false, which means that it is not at the trigger position by default.
isPlay: The default is false, which means that there is no music playing by default, which is used to deal with the situation of pressing the down key multiple times in a row

blueprint design

blueprint design

Guess you like

Origin blog.csdn.net/Kandy0125/article/details/115617148