Why does this not work?

I’m trying to make it really easy to rotate a cube when pressing the E key.

I don’t get any errors or anything, but when I play and press or hold E, nothing happens. How can make an object rotate around the y-axis easily?

This is my code:

public float clockwise = 5.0f;

void Update() {
    if(Input.GetKey(KeyCode.E)) { 			
        transform.rotation = Quaternion.Euler(0, Time.deltaTime * clockwise, 0);
    } 
}

Time.deltaTime is the number of seconds elapsed since the last frame. Let’s assume your game runs at a solid 60FPS, in which case this will have a value each frame of 1/60 = 0.0167. Your current code then sets the rotation of the cube to be 5 * 0.0167 = about 0.083 degrees, and does not change from frame to frame.

To fix, replace:

transform.rotation = Quaternion.Euler(0, Time.deltaTime * clockwise, 0);

with:

transform.Rotate(0, Time.deltaTime * clockwise, 0);

Hi, because Time.deltaTime is time spend between two following frames, so the result of the multiplication is some random value close to 0 (depends on framerate);

Try instead:

transform.RotateAround (Vector3.zero, Vector3.up, Clockwise * Time.deltaTime);

or:

angle += Time.deltaTime * clockwise; // angle must be declared as a property or field 
transform.rotation = Quaternion.Euler(0, angle, 0);