Rotating and object on press then it reverting on release.

While I know it’s probably a simple answer, I was wondering how to make an object rotate a fixed amount on keypress and when its released for it to go back to its original rotation.

Ensure that object has a collider attached and attach a script containing the variables and functions from below:

private Quaternion notRotated;
public Quaternion rotated;
void Start() {
        notRotated = transform.rotation;

void OnMouseDown() {
        transform.rotation = rotated;

void OnMouseUp() {
        transform.rotation = notRotated;