reset rotaion

i’m having some trouble resetting my object back to its original position
here’s my code, it rotates fine

if (playerHealth < 50 && playerHealth > 0) {
		
		
		rotateBar=0.02f * (rotateSpeed / (playerHealth / 100));
		transform.Rotate (0, 0, rotateBar);
		
	}
	
	else  {
		
	transform.Rotate(Vector3.zero);
	}

the last line should be

 transform.rotation = Quaternion.identity;

This is because ‘rotate’ offsets the current rotation so if you had a rotation of 0,0,90 and you did rotate Vector3.zero you end up with 0,0,90 + 0,0,0 = 0,0,90

Transform.Rotate applies a rotation, it doesn’t set it.

You can reset the world rotation with

transform.rotation = Quaternion.identity;

or you can just store your original rotation in a variable then apply it afterwards.

the above method works if the object is in world position however local position its doesn’t work.

the object is attached to the main camera. i did fix the issue , but i used animations instead, so i had a few frames with the position reset.