I have several DamageTypes. I want to do something special for Character depending on what DamageType have taken.
Now I use this code for solve my problem. But I don't want to use IF statements + casting!
float ABaseCharacter::TakeDamage(float Damage, struct FDamageEvent const& DamageEvent, class AController* EventInstigator, class AActor* DamageCauser)
{
UDamageType *DamageType = Cast<UMyDamageType1>(DamageEvent.DamageTypeClass->GetDefaultObject());
if (DamageType){
//do something
}
DamageType = Cast<UMyDamageType2>(DamageEvent.DamageTypeClass->GetDefaultObject());
if (DamageType){
//do something
}
// and there will be many same code (copy-paste) because
// I need to find what DamageType I got.
return Damage;
}
Is there more elegant solution?
Aucun commentaire:
Enregistrer un commentaire