Setup Mission End

编写FPSGameMode

新建函数OnMissionComplete,并设置为蓝图可实现事件

    UFUNCTION(BlueprintImplementableEvent,Category="GameMode")
    void OnMissionComplete(APawn* InstigatorPawn);

新建函数CompleteMission

void CompleteMission(APawn* InstigatorPawn);//确保其设在public下,能够从ExtractionZone调用

实现

void AFPSGameMode::CompleteMission(APawn* InstigatorPawn)
{
    if (InstigatorPawn)
    {
        InstigatorPawn->DisableInput(nullptr);//禁用玩家控制器对它的控制
    }
    OnMissionComplete(InstigatorPawn);
}

实现HandleOverlap函数

void AFPSExtractionZone::HandleOverlap(UPrimitiveComponent * OverlappedComponent, AActor * OtherActor, UPrimitiveComponent * OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult & SweepResult)
{

    AFPSCharacter* MyPawn = Cast<AFPSCharacter>(OtherActor);
    if (MyPawn == nullptr)
    {
        return;
    }
    if (MyPawn->bIsCarryingObjective)
    {
        AFPSGameMode* GM = Cast<AFPSGameMode>(GetWorld()->GetAuthGameMode());
        if (GM)
        {
            GM->CompleteMission(MyPawn);
        }
    }
    else
    {
        UGameplayStatics::PlaySound2D(this, ObjectiveMissingSound);
    }
}

 

posted @ 2019-02-07 15:21  CodeWithMe  阅读(279)  评论(0编辑  收藏  举报