编辑ABatteryCollectorCharacter::CollectPickups
void ABatteryCollectorCharacter::CollectPickups()
{
TArray<AActor> CollectedActors;
CollectionSphere->GetOverlappingActors(CollectedActors);
float CollectedPower = 0;
for (int32 iCollected = 0; iCollected < CollectedActors.Num(); ++iCollected)
{
APickUp const TestPickup = Cast<APickUp>(CollectedActors[iCollected]);
if (TestPickup && !TestPickup->IsPendingKill() && TestPickup->IsActive())
{
TestPickup->WasCollected();
ABatteryPickUp* const TestBattery = Cast<ABatteryPickUp>(TestPickup); //用于判断PickUp是不是BatteryPickUp
if (TestBattery)
{
CollectedPower += TestBattery->GetPower(); // 更新Power
}
TestPickup->SetActive(false);
}
}
if (CollectedPower > 0)
{
UpdatePower(CollectedPower); // 更新Power
}
}
运行 观察Character 的CharacterPower属性 当人物走到电池身边时 按C 数值增加