A man has died and an eight-year-old girl has been taken to hospital after a fire at a four-storey building in Scotland.