示例#1
0
void APickUpItem::Prox_Implementation(AActor* OtherActor, UPrimitiveComponent* OtherComp, int32
	OtherBodyIndex, bool bFromSweep, const FHitResult & SweepResult)
{
	// if the overlapped actor is NOT the player,
	// you simply should return
	if (Cast<AActor>(OtherActor) == nullptr)
	{
		return;
	}
	// Get a reference to the player avatar, to give him
	// the item
	AAvatar *avatar = Cast<AAvatar>(UGameplayStatics::GetPlayerPawn(
		GetWorld(), 0));
	// Let the player pick up item
	// Notice use of keyword this!
	// That is how _this_ Pickup can refer to itself.
	avatar->Pickup(this);
	
	if (CoinSound != NULL)
	{
		UGameplayStatics::PlaySoundAtLocation(this, CoinSound, GetActorLocation());
	}
	// Get a reference to the controller
	APlayerController* PController = GetWorld() ->GetFirstPlayerController();
	// Get a reference to the HUD from the controller
	AMyHUD* hud = Cast<AMyHUD>(PController->GetHUD());
	hud->addMessage(Message(Icon, FString("Picked up ") + FString(" ") + Name + FString(" ")+FString::FromInt(Quantity), 2.0f, FColor::Black, FColor::Black));
	Destroy();

	
}
示例#2
0
void ANPCDialogue::Prox_Implementation(AActor* otherActor, UPrimitiveComponent* 
	otherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult & SweepResult)
{
	if (Cast<AFPSHorrorCharacter>(otherActor) == nullptr)
	{
		return;
	}
	APlayerController* PController = GetWorld()->GetFirstPlayerController();
	if (PController)
	{
		AMyHUD* hud = Cast<AMyHUD>(PController->GetHUD());
		hud->addMessage(FMessage(NPCmessage, 5.0f, FColor::White));
	}
}