Update Character for Random Craving

This commit is contained in:
Philip W 2024-01-27 12:56:23 +00:00
parent 243e4465ab
commit ec609c72bf
5 changed files with 24 additions and 1 deletions

BIN
SeagullGame/Content/Items/BPI_CubeTransparent.uasset (Stored with Git LFS) Normal file

Binary file not shown.

BIN
SeagullGame/Content/Items/M_CravingTransparent.uasset (Stored with Git LFS) Normal file

Binary file not shown.

Binary file not shown.

View File

@ -136,6 +136,19 @@ void ASeagullGameCharacter::StartGame()
GetWorld()->GetTimerManager().ClearTimer(GameTimerHandle);
}
GetWorld()->GetTimerManager().SetTimer(GameTimerHandle, this, &ASeagullGameCharacter::EndGame, GameTime, false);
FTimerHandle CravingTimerHandle;
GetWorld()->GetTimerManager().SetTimer(CravingTimerHandle, [this]()
{
TSubclassOf<AItemActor> ItemActor = ItemActors[FMath::RandRange(0, ItemActors.Num() - 1)];
if (IsValid(CravingItemActor)) CravingItemActor->Destroy();
CravingItemActor = GetWorld()->SpawnActor(ItemActor);
CurrentCraving = Cast<AItemActor>(CravingItemActor)->ItemType;
CravingItemActor->SetActorEnableCollision(false);
USkeletalMeshComponent* MeshComponent = GetMesh();
if (!MeshComponent->HasAnySockets()) return;
CravingItemActor->AttachToComponent(MeshComponent, FAttachmentTransformRules::SnapToTargetNotIncludingScale, "CravingSocket");
}, 30, true, 3);
}
void ASeagullGameCharacter::EndGame()

View File

@ -100,6 +100,10 @@ public:
UBoxComponent* PickupBox;
UPROPERTY(BlueprintReadOnly, Category = "Item")
EItemType CurrentCraving;
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Item")
TArray<TSubclassOf<AItemActor>> ItemActors;
UPROPERTY(BlueprintReadOnly, Category = "Item")
AActor* CravingItemActor;
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "John")
float JohnsCurrentHunger = 0;