You need a Damage Detection System
Or you can use another function but only with JASS
Or with GUI the first thing that comes to my mind is to create a timer, and check for the unit life, if the life is lower than it's initial value, then the unit has taken damage