c++:
Код: Выделить всё
#include "MechanicMike_BreakableBlock.h"
#include "MechanicMike.h"
#include "PaperSpriteComponent.h"
#include "Components/BoxComponent.h"
// Sets default values
AMechanicMike_BreakableBlock::AMechanicMike_BreakableBlock()
{
// 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;
MySprite = CreateDefaultSubobject(TEXT("Breakable Block"));
MyBreakableTrigger = CreateDefaultSubobject(TEXT("Breakable Trigger"));
RootComponent = MyBreakableTrigger;
MySprite->SetupAttachment(RootComponent);
}
// Called when the game starts or when spawned
void AMechanicMike_BreakableBlock::BeginPlay()
{
Super::BeginPlay();
MyBreakableTrigger->OnComponentHit.AddDynamic(this, &AMechanicMike_BreakableBlock::OnBlockHit);
}
// Called every frame
void AMechanicMike_BreakableBlock::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
void AMechanicMike_BreakableBlock::OnBlockHit(UPrimitiveComponent* HitComponent, AActor* OtherActor,
UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit)
{
if (OtherActor->IsA(AMechanicMike::StaticClass()))
{
BlockDestroy();
}
}
void AMechanicMike_BreakableBlock::BlockDestroy()
{
if (!IsPendingKillPending())
{
Destroy();
}
}
Подробнее здесь: https://stackoverflow.com/questions/784 ... the-engine