Set a constant rotation in an updating function in C#?

I know this is a basic syntax question but how do I set the rotation of an object in a function such as an update function or in an OnCollisionStay function? Like i would want the rotation of a camera object to have an x rotation of 10 in the OnCollisionStay function but in the OnCollisionExit function i would want the x rotation to be 0. When i use transform.Rotate the object keeps spinning hahaha :stuck_out_tongue:

You can use transform.eulerAngles to set some fixed rotation (eulerAngles are those nice xyz angles you see in Inspector/Transform/Rotation), like this:

bool lookUp = false;

void Update(){
  Vector3 euler = transform.eulerAngles;
  euler.x = lookUp? 30 : 0; // set angle around x to 30 or 0, according to lookUp
  transform.eulerAngles = euler;
}

void OnCollisionEnter(col: Collision){
  lookUp = true;
}

void OnCollisionExit(col: Collision){
  lookUp = false;
}

I had a bad experience changing movement or rotation inside OnCollision events, thus in this case I just set/cleared a boolean flag, and selected the x angle in Update.