memo 14  C++ 배터리 콜렉터 05 , 6 , 7 , 8 , 9 , 10


C++ Battery Collector: Extending the Pickup Class | 05 | v4.9 Tutorial Series | Unreal Engine






파생 클래스 생성



또는


모든 클래스 표시로 부모클래스 정하기









C++ Battery Collector: Creating the Spawning Volume | 06 | v4.9 Tutorial Series | Unreal Engine






#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);
}





C++ Battery Collector: Defining What to Spawn | 07 | v4.9 Tutorial Series | Unreal Engine



UPROPERTY(EditAnyWhere,Category="Spawning")
TSubclassOf<class APickup> WhatToSpawn;



TSubclassOf<class APickup> WhatToSpawn;


UPROPERTY(EditAnyWhere,Category="Spawning")






C++ Battery Collector: Setting Timers for Spawning | 08 | v4.9 Tutorial Series | Unreal Engine


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;









C++ Battery Collector: Extending the Character Class | 09 | v4.9 Tutorial Series | Unreal Engine





C++ Battery Collector: Collecting Pickups | 10 | v4.9 Tutorial Series | Unreal Engine




h

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);
              }
       }
}

여기 까지 작업 소스




















+ Recent posts