Use Lerp to rotate object

void Update () {
transform.Translate (Vector3.right * speed * Time.deltaTime);

		if (Input.GetKeyDown (KeyCode.W)) 
		{
			transform.localEulerAngles = new Vector3(0,0,90);
		}
		if (Input.GetKeyDown (KeyCode.D)) 
		{
			transform.localEulerAngles = new Vector3(0,0,0);
		}
		if (Input.GetKeyDown (KeyCode.S)) 
		{
			transform.localEulerAngles = new Vector3(0,0,-90);
		}
		if (Input.GetKeyDown (KeyCode.A)) 
		{
			transform.localEulerAngles = new Vector3(0,0,180);
		}
	}

with this simple arrangement i am able to rotate the object but how can i rotate it smoothly.

I can not find lerp function which accepts current rotation and future rotation and some float.

please help.

I’d go with Quaternion.RotateTowards, as it’s nice and compact. Example for W:

if (Input.GetKeyDown (KeyCode.W)) 
{
    Quaternion currentRotation = transform.rotation;
    Quaternion wantedRotation = Quaternion.Euler(0,0,90);
    transform.rotation = Quaternion.RotateTowards(currentRotation, wantedRotation, Time.deltaTime * rotateSpeed);
}

Where rotateSpeed is a float variable just like speed. This will work for the majority of cases- lerping takes quite a bit of extra maths to get right if the distance you’re going to rotate varies.

use transform.rotation : Unity - Scripting API: Transform.rotation

convert to quaternion (or replace current euler values) : Unity - Scripting API: Quaternion.Euler

slerp : Unity - Scripting API: Quaternion.Slerp

how to correctly lerp : Using Vector3.Lerp() correctly in Unity — One Man's Trash is Another Man's Blog

difference between lerp and slerp : Quaternion Slerp v.s. Matrix Lerp - YouTube