Existence of a semicontinuous or continuous utility function: a unified approach and an elementary proof