Ophelia references an action that apparently occurred before this particular scene which does not ever occur in the play for the audience to see. She reports to her father:
My lord, as I was sewing in my closet,
Lord Hamlet, with his doublet all unbraced,
No hat upon his head, his stockings fouled,
Ungartered, and down-gyved to his ankle;(90)
Pale as his shirt, his knees knocking each other,
And with a look so piteous in purport,
As if he had been loosed out of hell
To speak of horrors, he comes before me.
In modern English, Ophelia essentially said that Hamlet's shirt was unbuttoned, he had no hat, his tights had fallen to his ankles, his face was pale, his knees were shaking, and he looked like he just came out of hell. This appearance of Hamlet's cold be interpreted as if he was undressing himself for Ophelia, but as the description ends he seems very afraid. He does actions that demonstrate nervousness and he appears as if he saw something that filled him with fear.
Ophelia described the situation as creating fear in her. Hamlet looked like this because he had just seen the ghost of his father.