Rotating a model during runtime

Hello I'm trying to rotate a model during runtime by using the keys 'A' and 'D'. I am using the following code segment. Speed is set to .5 right now.

//Rotate Left
if(Input.GetKey(KeyCode.A) && !Input.GetKey(KeyCode.D))
    transform.rotation.y = transform.rotation.y - speed;

//Rotate Right
if(Input.GetKey(KeyCode.D) && !Input.GetKey(KeyCode.A))
    transform.rotation.y = transform.rotation.y + speed;

The model does rotate, but it seems like an accelerated rotate. At first it goes really slow and then super fast and then stops. I would like it to just rotate continuously. Any way to that while still using GetKey?

transform.rotation is a quaternion; don't set it unless you're familiar with quaternions. Use transform.Rotate() instead, and also instead of hard-coding keys, use Input.GetAxis. You also need to use Time.deltaTime to make your code not be framerate-dependent.

transform.Rotate(0, Input.GetAxis("Horizontal") * 3, 0);

Please note that the number 3 can be changed in order to make the rotation faster or slower.

If you would like to do it with Physics:

rigidbody.AddRelativeTorque(0, Input.GetAxis("Horizontal") * 3, 0);

Again, change the number 3 to make it go faster or slower

GetKey will be true on each frame the key is held, so yeah, your rotation will increment/decrement each frame, that's acceleration.

You could use GetKeyDown to start it, and GetKeyUp to stop it.

Or you could set a boolean 'flag' variable that indicates the inc/dec has already been done.

Or you might try removing the variable that's getting munged:

transform.rotation.y = -speed;

for example