memo 14 C++ 배터리 콜렉터 05 , 6 , 7 , 8 , 9 , 10
파생 클래스 생성
또는
모든 클래스 표시로 부모클래스 정하기
#include "SpawnVolume.h"
#include "Components/BoxComponent.h"
#include "Kismet/KismetMathLibrary.h"
// Sets default values
ASpawnVolume::ASpawnVolume()
{
// 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;
// Create the box Component to represetn the spawn vloume
WhereToSpawn = CreateDefaultSubobject<UBoxComponent>(TEXT("WhereToSpawn"));
RootComponent = WhereToSpawn; ( fixed error )
}
FVector ASpawnVolume::GetRandomPointInVolume()
{
FVector SpawnOrigin = WhereToSpawn->Bounds.Origin;
FVector SpawnExtent = WhereToSpawn->Bounds.BoxExtent;
return UKismetMathLibrary::RandomPointInBoundingBox(SpawnOrigin, SpawnExtent);
}
UPROPERTY(EditAnyWhere,Category="Spawning")
TSubclassOf<class APickup> WhatToSpawn;
TSubclassOf<class APickup> WhatToSpawn;
UPROPERTY(EditAnyWhere,Category="Spawning")
h
class TUTORIAL_BATTERYCOLL_API ASpawnVolume : public AActor
FTimerHandle spawnTimer;
/* Minimum spawn delay */
UPROPERTY(EditAnyWhere, BlueprintReadWrite, Category = "Spawning")
float spawnDelayRangeLow;
/* Maximum spawn delay */
UPROPERTY(EditAnyWhere, BlueprintReadWrite, Category = "Spawning")
float spawnDelayRangeHigh;
class ATutorial_BatteryCollCharacter : public ACharacter
/** Collection sphere*/
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = "true"))
class USphereComponent* CollectionSphere;
UFUNCTION(BlueprintCallable, Category="Pickups")
void CollectPickups();
cpp
ATutorial_BatteryCollCharacter::ATutorial_BatteryCollCharacter()
{
//Create the collection sphere
CollectionSphere = CreateDefaultSubobject<USphereComponent>(TEXT("CollectionSphere"));
CollectionSphere->AttachTo(RootComponent);
CollectionSphere->SetSphereRadius(200.f);
// Input
void ATutorial_BatteryCollCharacter::SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent)
{
PlayerInputComponent->BindAction("Collect", IE_Pressed, this, &ATutorial_BatteryCollCharacter::CollectPickups);
void ATutorial_BatteryCollCharacter::CollectPickups()
{
// Get all overlapping Actors and store them in an array
TArray<AActor*> CollectedActors;
CollectionSphere->GetOverlappingActors(CollectedActors);
// For each Actor we collected
for (int32 iCollected = 0; iCollected < CollectedActors.Num(); iCollected++)
{
// Cast the actor to APickup
APickup* const testPickup = Cast<APickup>(CollectedActors[iCollected]);
// If the cast is successful and the pickup is valid and active
if (testPickup && !testPickup->IsPendingKill() && testPickup->IsActive())
{
// call the pickup's WasCollected function
testPickup->WasCollected();
// Decativate the pickup
testPickup->SetActive(false);
}
}
}
여기 까지 작업 소스
'DailyUnreal' 카테고리의 다른 글
Unreal. UE_LOG. 로그 카테고리 등록 방법 (0) | 2020.02.26 |
---|---|
Unreal. struct. header. error : Unrecognized type (0) | 2020.02.25 |
memo 13 C++ 배터리 콜렉터 04 (0) | 2018.08.17 |
memo 12 C++ 배터리 콜렉터 03 (0) | 2018.08.17 |
memo 11 C++ 배터리 콜렉터 02 (0) | 2018.08.17 |