Create Destructible Actor Class
This commit is contained in:
		
							parent
							
								
									fc71693a42
								
							
						
					
					
						commit
						19a5054271
					
				
							
								
								
									
										35
									
								
								Source/Nakatomi/Destructable.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								Source/Nakatomi/Destructable.cpp
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,35 @@ | |||||||
|  | // Fill out your copyright notice in the Description page of Project Settings.
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | #include "Destructable.h" | ||||||
|  | #include <Kismet/GameplayStatics.h> | ||||||
|  | 
 | ||||||
|  | // Sets default values
 | ||||||
|  | ADestructable::ADestructable() | ||||||
|  | { | ||||||
|  |  	// Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
 | ||||||
|  | 	PrimaryActorTick.bCanEverTick = false; | ||||||
|  | 	 | ||||||
|  | 	StaticMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("StaticMeshComponent")); | ||||||
|  | 
 | ||||||
|  | 	this->Tags.Add(FName("Destructable")); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | // Called when the game starts or when spawned
 | ||||||
|  | void ADestructable::BeginPlay() | ||||||
|  | { | ||||||
|  | 	Super::BeginPlay(); | ||||||
|  | 
 | ||||||
|  | 	if (!this->ActorHasTag(FName("Destructable"))) | ||||||
|  | 	{ | ||||||
|  | 		this->Tags.Add(FName("Destructable")); | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void ADestructable::Destruct() | ||||||
|  | { | ||||||
|  | 	// TODO: Add some more logic here
 | ||||||
|  | 	 | ||||||
|  | 	UGameplayStatics::SpawnEmitterAtLocation(this, ParticleEffect, this->ActorToWorld().GetLocation(), FRotator::ZeroRotator, true); | ||||||
|  | 	Destroy(); | ||||||
|  | } | ||||||
							
								
								
									
										32
									
								
								Source/Nakatomi/Destructable.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								Source/Nakatomi/Destructable.h
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,32 @@ | |||||||
|  | // Fill out your copyright notice in the Description page of Project Settings.
 | ||||||
|  | 
 | ||||||
|  | #pragma once | ||||||
|  | 
 | ||||||
|  | #include "CoreMinimal.h" | ||||||
|  | #include "GameFramework/Actor.h" | ||||||
|  | #include "Destructable.generated.h" | ||||||
|  | 
 | ||||||
|  | UCLASS() | ||||||
|  | class NAKATOMI_API ADestructable : public AActor | ||||||
|  | { | ||||||
|  | 	GENERATED_BODY() | ||||||
|  | 	 | ||||||
|  | public:	 | ||||||
|  | 	UPROPERTY(EditDefaultsOnly, BlueprintReadWrite) | ||||||
|  | 	class UParticleSystem* ParticleEffect; | ||||||
|  | 
 | ||||||
|  | 	UPROPERTY(EditDefaultsOnly, BlueprintReadWrite) | ||||||
|  | 	class UStaticMeshComponent* StaticMesh; | ||||||
|  | 
 | ||||||
|  | 	// Sets default values for this actor's properties
 | ||||||
|  | 	ADestructable(); | ||||||
|  | 
 | ||||||
|  | protected: | ||||||
|  | 	// Called when the game starts or when spawned
 | ||||||
|  | 	virtual void BeginPlay() override; | ||||||
|  | 
 | ||||||
|  | public: | ||||||
|  | 
 | ||||||
|  | 	void Destruct(); | ||||||
|  | 
 | ||||||
|  | }; | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user