UAudioComponent反复播放声音

时间:2020-09-17 16:58:46

标签: c++ unreal-engine4

这是代码

该代码应该在向前移动时播放步行声音,而在不移动时停止播放声音,而是在每帧都发出声音的声音中发出可怕的声音。

在cppp中

void AMain::MoveRight(float Value)
{
    if (!bIsDead && Value != 0.0f)
    {
        // add movement in that direction
        AddMovementInput(GetActorRightVector(), Value);
        if (!IsValid(WalkingSound))
        {
            WalkingSound = UGameplayStatics::SpawnSound2D(this, SoundBase);
            UE_LOG(LogTemp, Warning, TEXT("Play"));
        }
        bIsMovingRight = true;

    }
    else if (Value == 0.0f && IsValid(WalkingSound))
    {
        bIsMovingRight = false;
        WalkingSound->Stop();
        UE_LOG(LogTemp, Warning, TEXT("Stop"));
    }
    
}

在.h

UPROPERTY(EditDefaultsOnly)
        class USoundBase* SoundBase;

    class UAudioComponent* WalkingSound; 

0 个答案:

没有答案