Added : Attack function for enemies, callable in blueprint and overridable

This commit is contained in:
Emilie Schott 2025-01-24 11:19:39 +01:00
parent 7bb1926af2
commit 3b1d4c86e5
7 changed files with 30 additions and 3 deletions

Binary file not shown.

View File

@ -13,6 +13,11 @@ void ALMDistantEnemy::BeginPlay()
}
void ALMDistantEnemy::Attack(const APawn* TargetedPawn)
{
Super::Attack(TargetedPawn);
}
void ALMDistantEnemy::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);

View File

@ -13,6 +13,13 @@ void ALMEnemy::BeginPlay()
Super::BeginPlay();
}
void ALMEnemy::Attack(const APawn* TargetedPawn)
{
// TO DO
FString Debug = FString::Printf(TEXT("Enemy %s attack %s !"), *GetName(), *TargetedPawn->GetName());
GEngine->AddOnScreenDebugMessage(1, 2.f, FColor::Cyan, Debug);
}
double ALMEnemy::GetDistanceToTarget(const AActor* TargetedActor)
{
return (TargetedActor->GetActorLocation() - GetActorLocation()).Length();

View File

@ -14,6 +14,11 @@ void ALMMeleeEnemy::BeginPlay()
}
void ALMMeleeEnemy::Attack(const APawn* TargetedPawn)
{
Super::Attack(TargetedPawn);
}
void ALMMeleeEnemy::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);

View File

@ -18,5 +18,6 @@ public:
protected:
virtual void BeginPlay() override;
virtual void Attack(const APawn* TargetedPawn) override;
};

View File

@ -25,7 +25,7 @@ public:
protected:
virtual void BeginPlay() override;
UPROPERTY(EditAnywhere, BlueprintReadWrite, meta = (AllowPrivateAccess = "true"), Category = "Legumix")
EEnemyState EnemyState;
@ -39,4 +39,12 @@ protected:
*/
UFUNCTION(BlueprintCallable, Category="Legumix", meta=(ReturnDisplayName="Distance", DefaultToSelf="TargetedActor"))
double GetDistanceToTarget(const AActor* TargetedActor);
/**
* Returns the distance between the enemy and a target.
* @param TargetedPawn
* @returns
*/
UFUNCTION(BlueprintCallable, Category="Legumix", meta=(DefaultToSelf="TargetedPawn"))
virtual void Attack(const APawn* TargetedPawn);
};

View File

@ -18,5 +18,6 @@ public:
protected:
virtual void BeginPlay() override;
virtual void Attack(const APawn* TargetedPawn) override;
};