How to lock the rotation of an object on all axes?

How do I lock the rotation of an object via script?

Thanks in advance!

Couldn’t you just do:

var LockedRotation : Quarternion;
var Lock : boolean;

if (Lock) {
    if (LockedRotation == null) {
        LockedRotation = transform.rotation;
    }
    transform.rotation = LockedRotation
} else {
    if (LockedRotation != null) {
        LockedRotation = null;
    }
}