I apologise if this question is trivial. I don't know much about $C^*$-algebras and am learning the basics of the theory from I.F. Putnam's online notes Lecture Notes on $C^*$-Algebras.
Let $X$ be a locally compact Hausdorff space. In the linked notes, $C_0(X)$ is defined to consist of the continuous maps $f:X\to\mathbb{C}$ that vanish at infinity i.e. for which $$\{x\in X:|f(x)|\geq\epsilon\}$$ is a compact subset of $X$ for each $\epsilon>0$. Why must it be the case that $C_0(X)$ is unital iff $X$ is compact?
First of all, if we look at $C(X)$ (the algebra of continuous functions $f:X\to\mathbb{C})$, then the identity is the constant function $x\mapsto 1$, correct?
My intuition is telling me that this function would fail to be continuous if $X$ is non-compact. I don't know, I might be totally wrong. If someone could explain this, that would be great.
The constant function 1 is continuous no matter what $X$ is. This is extremely easy to prove from the basic definition of "continuous".
The problem is in the phrase "vanishes at infinity". If you study the definition of this term carefully, you should be able to prove that the constant function 1 vanishes at infinity if, and only if, $X$ is compact. Hence when $X$ is not compact, $1$ is not an element of $C_0(X)$.
You can then go on to show that if $C_0(X)$ does have a unit, it must be the constant function 1. So $C_0(X)$ is unital if and only if $X$ is compact.