Im currently trying to build a coin pick up ive so far managed to build the pick up, make it so it destroys itself once its picked up but now im trying to make it so when i pick one 1 will print out when i pick another one 2 will print out so in essence addin them up is my problem.
One way of doing it would be to add a function to your GameMode class that each coin calls when it is picked up. Then the game mode can increment a variable and print out a message.
Coin.cpp
void ACoin::OnPickedUp()
{
UWorld* World = GetWorld();
if( World )
{
AMyGameMode* GameMode = World->GetAuthGameMode<AMyGameMode>();
if( GameMode )
{
GameMode->CoinWasPickedUp(this);
}
}
// ...
}
MyGameMode.cpp
void AMyGameMode::CoinWasPickedUp(ACoin* Coin)
{
++NumCoinsCollected;
UE_LOG(LogActor, Log, TEXT("Picked up coin #%d"), NumCoinsCollected);
}
This didnt work for me i mean it helped me but i decided to set up the counter with the print string in the character side of things so now im just trying to figure out how to cast in the picked up function so i can use the fuctions and variables in the coin pick up thanks for the help !!! the cast part is a bit confusing if im going to cast in the picked up function how do i write it? I know it starts Cast(something)
To cast an actor to your character type you would do
AMyCharacter* Character = Cast<AMyCharacter>(OtherActor);
THANK YOU!!! IT WORKS!!!