how to make a smooth rotation of the object?

I use this script here to rotate the object to the desired degree, how to make the object rotate smoothly?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class mehanic : MonoBehaviour
{
   
    void FixedUpdate()
    {

        if (Input.GetKey(KeyCode.E))
        {
           
            transform.rotation = Quaternion.Euler(new Vector3(0, 0, -90));

        }
    }
}

You could use Quaternion.RotateTwoards

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class mehanic : MonoBehaviour
{
 
    void FixedUpdate()
    {
        if (Input.GetKey(KeyCode.E))
        {
         
            transform.rotation = Quaternion.RotateTowards(transform.rotation, Quaternion.Euler(new Vector3(0, 0, -90), 90f * Time.deltaTime);
        }
    }
}
3 Likes

thanks

You should the new code here because that one i think is for older versions of unity:

transform.rotation = Quaternion.RotateTowards(transform.rotation, Quaternion.Euler(0, 0, -20), 90f * Time.deltaTime);