Actually..instead of going through all that work its quite simple..You see every time a unit builds something they use a skill for it..For humans its Repair [Humans], for undead its Restore..so simply make a trigger like this..
Untitled Trigger 006
Events
Unit - A unit Stops casting an ability
Conditions
(Ability being cast) Equal to Repair (Human)
Actions
Unit - Remove (Casting unit) from the game
However this has a few drawbacks..like if you do make it this way, you cant move your unit while building..cause that will stop the ability and hence remove your unit...also..you cant repair buildings but since your making the unit be removed after building..it seems that this wont be a big problem..