Create it yourself.
For each unit in a map, give it a unique integer custom value which corresponds to array spots. Whenever a unit dies, pick the unit with the highest custom value and move all of its info to the dying unit's slot in the array.
He doesn't need to, blizzard already put one in... However for some reason I think they changed it.
Before a recent patch i'm assuming the function
UnitGetPropertyInt(u, 24, c_unitPropCurrent)
would return the unique id integer for the unit u, yet for some reason it's not working anymore.
I got this info from
http://www.sc2mapster.com/api-docs/functions/unit-get-property-int/
and when I first used it it was working fine. Though I'm assuming they might have added a property and changed the unique ID's integer.
I was using it in my map for a trade caravan but then after a recent patch they stopped working right, I noticed through a debug the functions topped getting the unique ID.
I'm looking to see what blizzard changed it too, but it's definately in there.
Edit: Nevermind I just found it, apparently to make it work you gotta put any value 24 or above, but since 24 and such don't work, that can mean blizzard probably put something there, don't know what it is but since it just has to be anything above, you can just use something insane like 9000.
so to get a units unique ID, use the function
UnitGetPropertyInt(u, 9000, c_unitPropCurrent)
9000 can be any number thats really high, 24 and below will give specific unit values like health and health percentage. But any number that doesn't have a specific value will return the unique ID.
Hope this was able to help.