It is known that $\text{Mor}(X,Y)$ is in bijective correspondence with $\text{Hom}(\mathcal{O}_Y(Y), \mathcal{O}_X(X))$, provided $Y$ is an affine scheme. I do not understand a small but crucial part of the surjectivity statement, and my question concerns this.
Suppose $Y=\text{Spec} A$ and $X$ is covered by affine subschemes: $\{U_i=\text{Spec} B_i\}_i$. If we are given a ring morphism $\phi :A=\mathcal{O}_Y(Y)\rightarrow \mathcal{O}_X(X)$, $\phi$ can be composed with restriction maps to give $\phi_i : A \rightarrow \mathcal {O}_X(U_i) = B_i$. Then $\phi_i^{-1}$ induces affine scheme morphism $f_i:\text{Spec} B_i \rightarrow \text{Spec} A$.
Now supposedly these affine scheme morphisms should agree on intersections. If they agree, the morphisms can be glued to obtain a morphism from $X$ to $Y$, and this gives the surjectivity. But I do not understand why any two morphisms should ever agree on the intersection. Qing Liu says that they should somehow obviously agree on affine subsets of the intersection, and I do not understand why that should happen either. Could anyone please be kind enough to explain this supposed triviality to me?
If anyone still has the patience to read, let me explain what I am worried about in the supposed compatibility. You see, scheme structure of $X$ imposes no restriction whatsoever to the isomorphisms $U_i \cong \text{Spec} A_i$. If we composed some nontrivial scheme automorphism of $\text{Spec} A_i$ with this isomorphism (say, the automorphism on $\text{Spec} R[x,y]$ induced by exchange of $x$ and $y$) and replace the original morphism, then even if morphisms $\{\text{Spec} A_i\rightarrow \text{Spec} R\}$ previously agreed, the effect of the automorphism might cause the morphisms to agree no longer. Maybe such automorphism has no effect when composed with restriction map from ring of global sections?? At least this seemed to be the case when I tried this with affine subsets of projective 2-space $\mathbb P_R^2$.