The definition says $\forall\varepsilon>0\ \exists\delta>0\cdots\cdots\cdots\cdots$. To prove that a function is uniformly continuous, you need to find $\delta$ as a function of $\varepsilon$ and prove that it's small enough. You know you've got $\delta_1$ that's small enough on one set and $\delta_2$ that's small enough on the other. Which one is smaller might depend on $\varepsilon$. However $\min\{\delta_1,\delta_2\}$ will be small enough on both sets.
Later note, per comments: Let's make $\delta_A$ small enough so that if $x,y\in A$ and $|x-y|<\delta_A$ then $|f(x)-f(y)|<\varepsilon/2$, and if $x,y\in B$ and $|x-y|<\delta_B$ then $|f(x)-f(y)|<\varepsilon/2$.
Let $\delta=\min\{\delta_A,\delta_B\}$.
If $x,y\text{ both}\in A$ or $\text{both}\in B$, and $|x-y|<\delta$ that does it, as above.
If $x\in A$ and $y\in B$, then the distances from $x$ to the boundary point $b$, and from $y$ to $b$, are less than $\delta$, so
$$|f(x)-f(y)| \le|f(x)-f(b)|+|f(b)-f(y)|<\frac\varepsilon2+\frac\varepsilon2=\varepsilon.$$
So in all cases, $|x-y|<\delta$ implies $|f(x)-f(y)|<\varepsilon$.
Your idea with $f_n=x^n$ is right. Use these as your sets : $E_0 = \left\{1\right\}$ and $E_k=\left[0,1-k^{-1}\right]$.
Just as you said, $f_n\rightarrow0$ on all $E_k$, for $k\geq1$, and on $E_0$, we have that $f_n(1)=1 \,\,\forall n$. Furthermore, the union of all $E_k, k\geq0$ is the unit interval, on which $f_n$ does not converge uniformly.
Best Answer
Let $D_1 = [-1, 0] \cup (1, 2]$ and $D_2 = [0, 1]$
Define $f(x) = 0$ on $[-1, 0]$; $f (x) = x $ on $[0, 1]$; $f(x) = 0 $ on $(1, 2]$
$f$ is separately UC on $D_1, D_2$ but discontinuous on $[-1, 2]$
The key to constructing the counterexample is that $D_1, D_2$ must share some part of their boundary in order to have at least one point in common, but then uniform continuity will be preserved at the intersection. So, it's set up so that $D_1, D_2$ can meet without intersecting somewhere else. One could construct counterexamples in the plane where $D_1, D_2$ are each connected sets and intersect on part of their boundary but only meet on another part. For example let the line $(0, -1)$ to $ (0, +1)$ be the boundary between $D_1, D_2$ with $D_1$ to the left and $D_2$ to the right. Let both include the line $(0, -1) $ to $(0, 0)$ so the intersection is non-empty, but only one include $(0, 0 )$ to $(0, 1)$ with the other being open up to this line.