If you are attacking (any action, spell, or ability that grants you an Attack Roll) from hiding and are unseen as with a successful Stealth Check, you gain advantage and are right to assume it's a condition for Advantage with a ranged weapon or spell attack.
Now that we know the above is 'Yes'; we can follow that once you make the initial attack (hit or miss) you give away your position and are no longer unseen/hidden. Should you succeed in another stealth check (relocating in the process or otherwise vanishing from sight once more) , you are once again fulfilling the conditions for gaining Advantage through attacking unseen.
Your example, with rules as written, would be more like the following:
Hidden Archer fires at a target that is currently unaware of her. Making the attack gives away her position and makes her target aware of her presence. She then ducks back into the cover of the building, because she must break line of sight before attempting to hide again (since you can not hide from something that can see you). She successfully conceals herself from detection once more and hurries to a different position. The target fails in locating her (using it's perception), and when she's able to take another shot on a future turn, she has advantage once more. Rinse and repeat until something breaks this cycle.
Of note, keep in mind that making an attack (taking the Attack Action), and trying to hide (taking the Hide Action), are both separate actions. Generally you only get 1 action per turn and unless something is allowing you to hide as a bonus action or for free (as cunning rogues are like to do); you wont be able to attack, hide, then attack next turn. More often than not you will attack unseen, spend your next turn breaking line of sight and/or hiding again, then attack unseen again on your third turn.