Post

UE5 增强输入触发器“已按下”机制

在Input Map中,为操作同时设定已按下和已松开触发器时,C++中,将函数绑定到 Triggerd 时,一次点击按键会触发两次,按下时,Value.Get<float>() 为1,松开时为0

1
Input->BindAction(AimPressedAction, ETriggerEvent::Triggered, this, &AShooterCharacter::CharacterAim);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
void AShooterCharacter::CharacterAim(const FInputActionValue& Value)  
{  
    if (Value.Get<float>() == 1)  
    {  
       bAiming = !bAiming;  
  
       if (bAiming)  
       {  
          GetFollowCamera()->SetFieldOfView(CameraZoomedFOV);  
       }  
       else  
       {  
          GetFollowCamera()->SetFieldOfView(CameraDefaultFOV);  
       }  
    }  
  
    // UE_LOG(LogTemp, Warning, TEXT("%f"), Value.Get<float>())  
    // 为0时表示松开,为1时代表按下  
}
This post is licensed under CC BY 4.0 by the author.