Let $X$ a metric space, $\{U_i\}$ a collection of non-empty closed sets whose union is all of $X$. Give an example of a function $f:X\rightarrow \mathbb{R}$ such that the restriction $f|_{U_i}$ is continuous for all $i$ but $f$ is not continuous.
I was thinking for a step function and consider $X=[0,1]\subset \mathbb{R}$ with the induced metric, $U_i=[i/n,(i+1)/n]$ for $i=0,\dots,n-1$, but it seems that this type of example doesn't work.
For $X=\mathbb{R}$ take the closed sets $U_0=(-\infty,0]$ and $U_i=[\frac{1}{i},\infty)$ where $i$ is a positive integer.
Take the function prescribed by $x\mapsto1$ if $x>0$ and $x\mapsto0$ otherwise.
The restricted functions are even constant (so continuous for every topology on $\mathbb R$) and if $\mathbb R$ is equipped with e.g. its usual metrizable topology then the function is evidently not continuous at $0$.