Here's the idea. Say you want your function to be f(t) for t < 0, g(t) between 0 and 2, h(t) between 2 and 4, and 0 for t > 4.
So start building your function with f(t). At t=0 you want to get rid of f and start g:
f(t) + (g(t) - f(t))u(t)
At 2 you want to get rid of the g and start h
f(t) + (g(t) - f(t))u(t) + (h(t) - g(t))u(t-2)
At t = 4 you want to get rid of the h.
f(t) + (g(t) - f(t))u(t) + (h(t) - g(t))u(t-2) - h(t)u(t-4)
and you are done. Equivalently you could collect terms on the functions:
f(t)(1 - u(t)) + g(t)(u(t)-u(t-2)) + h(t)(u(t-2)-u(t-4))
Sometimes terms like u(t-b)-u(t-a) are called filter functions because they just pick up whatever they are multiplied by between a and b.