// Project Lab - NHTV Igad

#include "UnrealProject.h"
#include "ParticleEffect.h"


AParticleEffect::AParticleEffect()
{
 	// 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;
	duration = 5.0f;
	RootComponent = particleComponent = CreateDefaultSubobject<UParticleSystemComponent>("PSys");
	followActor = nullptr;
}

void AParticleEffect::BeginPlay()
{
	Super::BeginPlay();
	
}

void AParticleEffect::Tick( float DeltaTime )
{
	Super::Tick( DeltaTime );
	duration -= DeltaTime;
	if (followActor)
		SetActorTransform(followActor->GetTransform());
	if (duration <= 0.0f)
	{
		Destroy();
	}
}

void AParticleEffect::Init(UParticleSystem* particleSystem, float duration)
{
	this->duration = duration;
	particleComponent->SetTemplate(particleSystem);
	particleComponent->InitializeSystem();
}

