Hello guys. I have this problem. I want to make a Box, to, when fallen into the box, set you back to the spawnpoint and play a sound. However, I can’t seem to get it compiled. Code:
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "GameFramework/Actor.h"
#include "BlockActor.generated.h"
UCLASS()
class MYPROJECT2_API ABlockActor : public AActor
{
GENERATED_BODY()
public:
// Sets default values for this actor's properties
ABlockActor();
// Called when the game starts or when spawned
virtual void BeginPlay() override;
// Called every frame
virtual void Tick( float DeltaSeconds ) override;
//The static mesh for the pickup
UShapeComponent* FinishLineBox;
UPROPERTY(EditAnywhere)
USoundBase *FinishSound;
UFUNCTION()
void TriggerEnter(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult & SweepResult);
};
// Fill out your copyright notice in the Description page of Project Settings.
#include "MyProject2.h"
#include "BlockActor.h"
// Sets default values
ABlockActor::ABlockActor()
{
// 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;
FinishLineBox = CreateDefaultSubobject<UBoxComponent>(TEXT("FinishBox"));
RootComponent = FinishLineBox;
FinishLineBox->bGenerateOverlapEvents = true;
FinishLineBox->OnComponentBeginOverlap.AddDynamic(this, &ABlockActor::TriggerEnter);
}
// Called when the game starts or when spawned
void ABlockActor::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void ABlockActor::Tick( float DeltaTime )
{
Super::Tick( DeltaTime );
}
void TriggerEnter(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult & SweepResult)
{
if (OtherActor->IsA(ACharacter::StaticClass())) {
UGamePlayStatics::PlaySoundAttached(FinishSound, OtherActor->GetRootComponent());
}
}
Thanks in advance.
