UE5--011--Wall--VictoryBox


1. Wall

1.1 Wall.h

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "Wall.generated.h"

UCLASS()
class C005DODGEBALL_API AWall : public AActor
{
    GENERATED_BODY()
    
private:
    UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Wall, meta = (AllowPrivateAccess = "true"))
    class USceneComponent* RootScene;

public:    
    // Sets default values for this actor's properties
    AWall();

protected:
    // Called when the game starts or when spawned
    virtual void BeginPlay() override;

public:    
    // Called every frame
    virtual void Tick(float DeltaTime) override;

};


1.2 Wall.cpp

#include "Wall.h"
#include "Components/SceneComponent.h"

// Sets default values
AWall::AWall()
{
     // Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
    PrimaryActorTick.bCanEverTick = true;

    
    RootScene = CreateDefaultSubobject<USceneComponent>(TEXT("Root"));
    RootComponent = RootScene;

}

// Called when the game starts or when spawned
void AWall::BeginPlay()
{
    Super::BeginPlay();
    
}

// Called every frame
void AWall::Tick(float DeltaTime)
{
    Super::Tick(DeltaTime);

}


1.3 BP_Wall

image


2. VictoryBox

2.1 VictoryBox.h

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "VictoryBox.generated.h"

UCLASS()
class C005DODGEBALL_API AVictoryBox : public AActor
{
    GENERATED_BODY()
    
private:
    UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = VictoryBox, meta = (AllowPrivateAccess = "true"))
    class USceneComponent* RootScene;

    UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = VictoryBox, meta = (AllowPrivateAccess = "true"))
    class UBoxComponent* CollisionBox;

public:    
    // Sets default values for this actor's properties
    AVictoryBox();

protected:
    // Called when the game starts or when spawned
    virtual void BeginPlay() override;

public:    
    // Called every frame
    virtual void Tick(float DeltaTime) override;

    UFUNCTION()
    void OnBeginOverlap(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);

};


2.2 VictoryBox.cpp

#include "VictoryBox.h"
#include "Components/SceneComponent.h"
#include "Components/BoxComponent.h"
#include "../C005DodgeballCharacter.h"
#include "Kismet/KismetSystemLibrary.h"


// Sets default values
AVictoryBox::AVictoryBox()
{
     // Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
    PrimaryActorTick.bCanEverTick = true;

    RootScene = CreateDefaultSubobject<USceneComponent>(TEXT("Root"));
    RootComponent = RootScene;

    CollisionBox = CreateDefaultSubobject<UBoxComponent>(TEXT("Collision Box"));
    CollisionBox->SetupAttachment(RootComponent);
    CollisionBox->SetBoxExtent(FVector(60.0f, 60.0f, 60.0f));
    CollisionBox->SetRelativeLocation(FVector(0.0f, 0.0f, 120.0f));
    CollisionBox->OnComponentBeginOverlap.AddDynamic(this, &AVictoryBox::OnBeginOverlap);

}

// Called when the game starts or when spawned
void AVictoryBox::BeginPlay()
{
    Super::BeginPlay();
    
}

// Called every frame
void AVictoryBox::Tick(float DeltaTime)
{
    Super::Tick(DeltaTime);

}

void AVictoryBox::OnBeginOverlap(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
    if (Cast<AC005DodgeballCharacter>(OtherActor))
    {
        UKismetSystemLibrary::QuitGame(GetWorld(), nullptr, EQuitPreference::Quit, true);

    }
}


2.3 BP_VictoryBox

image


image

posted @ 2025-04-05 18:41  ParamousGIS  阅读(7)  评论(0)    收藏  举报