No. If you add a UnitAffectingCombat check there, you will never see a Combat icon, because the frame is created before anyone is in combat, so the check will prevent the Combat icon from being created in the first place.
All you need to do is create the icon; oUF will handle hiding it and showing it when needed. Just use the first (original) code block, but change:
Code:
if f.mystyle=="player" then
to:
Code:
if f.mystyle=="player" or f.mystyle=="target" then