示例#1
0
void AShell::OnHit(AActor* SelfActor, AActor *otherActor, FVector NormalImpulse, const FHitResult& Hit)
{
	if (GEngine){
		//If the object hit is a wall, check if it is a breakable wall, update its hit counter and "destroy" the
		//Wall if it has been hit 2 or more times. Allows the shell to bounce
		if (otherActor->GetActorLabel().Contains(TEXT("Wall"), ESearchCase::IgnoreCase, ESearchDir::FromEnd)){
			AWall* ThisWall = Cast<AWall>(otherActor);
			if (ThisWall->canBreak){
				ThisWall->hits++;
				if (ThisWall->hits >= 2){
					ThisWall->SetActorHiddenInGame(true);
					ThisWall->SetActorEnableCollision(false);
				}
			}
		}

		//If the object hit is an AI bot, update its hit counter and destroy the actor if it has been hit more than 3 times
		//Destroys the shell projectile on impact
		else if (otherActor->GetActorLabel().Contains(TEXT("Bot"), ESearchCase::IgnoreCase, ESearchDir::FromEnd)){
			ABot* ThisBot = Cast<ABot>(otherActor);
			ThisBot->hits += 1;
			if (ThisBot->hits >= 3){
				//Call the BotsDead function in HUD to decrement the number of bots alive
				AMyHUD* HUD = Cast<AMyHUD>(GetWorld()->GetFirstPlayerController()->GetHUD());
				HUD->BotsDead();
				otherActor->Destroy();
			}
			this->Destroy();
		}

		//If the object hit is a player tank, decrement the tank's health. Destroys the shell projectile on impact
		else if(otherActor->GetActorLabel().Contains(TEXT("Tank"), ESearchCase::IgnoreCase, ESearchDir::FromEnd)){
			AMyHUD* HUD = Cast<AMyHUD>(GetWorld()->GetFirstPlayerController()->GetHUD());
			HUD->LoseHealth();
			this->Destroy();
		}

		//If the object hit is a health pack, increment the tank's health. Destroys the shell projectile on impact
		else if (otherActor->GetActorLabel().Contains(TEXT("HealthPack"), ESearchCase::IgnoreCase, ESearchDir::FromEnd)){
			AMyHUD* HUD = Cast<AMyHUD>(GetWorld()->GetFirstPlayerController()->GetHUD());
			HUD->AddHealth();
			AHealthPack* ThisPack = Cast<AHealthPack>(otherActor);
			ThisPack->SetActorHiddenInGame(true);
			ThisPack->SetActorEnableCollision(false);
			this->Destroy();
		}
	}
}