Enemy Class

The enemy is an ACharacter & an IBulletHitInterface.
mail@pastecode.io avatar
unknown
c_cpp
2 years ago
2.0 kB
0
Indexable
Never
/*-----------------------------------------------------------------------------------------------------------*/

// IBulletHitInterface CLASS

#pragma once
#include "CoreMinimal.h"
#include "UObject/Interface.h"
#include "BulletHitInterface.generated.h"

// This class does not need to be modified.
UINTERFACE(MinimalAPI)
class UBulletHitInterface : public UInterface
{
	GENERATED_BODY()
};

class SHOOTER_API IBulletHitInterface
{
	GENERATED_BODY()

	// Add interface functions to this class. This is the class that will be inherited to implement this interface.
public:
	UFUNCTION(BlueprintNativeEvent, BlueprintCallable)
	void BulletHit(FHitResult HitResult);
};


/*-----------------------------------------------------------------------------------------------------------*/

// ENEMY CLASS

#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Character.h"
#include "BulletHitInterface.h"
#include "Enemy.generated.h"

UCLASS()
class SHOOTER_API AEnemy : public ACharacter, public IBulletHitInterface
{
	GENERATED_BODY()

public:
	AEnemy();

protected:
	virtual void BeginPlay() override;

	/** Particle to spawn when hit by bullets. */
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Combat, meta = (AllowPrivateAccess = "True"))
	class UParticleSystem* ImpactParticles;

	/** Sound to play when hit by bullets. */
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Combat, meta = (AllowPrivateAccess = "True"))
	class USoundCue* ImpactSound;

public:	
	virtual void Tick(float DeltaTime) override;

	virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;

	/*
	* This version is the overriden version. See "BulletHitInterface" file.
	* "UFUNCTION()" macro was inherited from the base version. 
	*/
	virtual void BulletHit_Implementation(FHitResult HitResult) override;
};

/*-----------------------------------------------------------------------------------------------------------*/