You can use Vector3.Lerp to transition from your current euler angles to a set of target angles 180 degrees around the y axis (Vector3.up).
public float smooth = 1f;
private Vector3 targetAngles;
void Update ()
{
if(Input.GetKeyDown(KeyCode.S)) // some condition to rotate 180
targetAngles = transform.eulerAngles + 180f * Vector3.up; // what the new angles should be
transform.eulerAngles = Vector3.Lerp(transform.eulerAngles, targetAngles, smooth * Time.deltaTime); // lerp to new angles
}
Just so you know, transform.eulerAngles is essentially the angles X, Y, and Z that appear under transform in the inspector.
You can also use Quaternions to do the same thing. It’s neater in code but slightly more performance costly. You can set the target rotation to the opposite direction you’re looking.
Here you go, my whole script for a jumping cube rotating an exact degree smoothly. Just modifiy it for your needs. It tried everything else too, but this was the only one which really works reliably even while jumping.