The Target type covers all of these cases - you just need to move the `var target = Target.FromActor(targetActor);` line outside this function.