How do you rotate the player and keep them there?

I know this is probably something very simple I’ve just forgotten, but I’m trying to make the player able to rotate 180 degrees and stay there, but at the moment they are only rotated for as long as the key is pressed. This is what I have:

if (CrossPlatformInputManager.GetButton("Turn"))
                transform.Rotate(Vector3.up, 180, Space.Self);

I wanted to make it so this happens smoothly in the space of about 1 second but I’d like to get the turning working first.

This is on the first person controller (albeit a slightly modified version, but nothing I’ve done would interfere with this) so it might be something on there that is messing it up. I’ve tried all kinds of things like different if statements, transforms and such even though the solution is probably much simpler than that. I am quite new to unity so pointers would be helpful.

Any help is appreciated :slight_smile:

To make sure you only rotate once you should try:


instead of:


The GetButton is true as long as the button is pressed, but the GetButtonDown is true only in the frame that the player pressed the button, more information here Unity - Scripting API: Input.GetButton and here Unity - Scripting API: Input.GetButtonDown

To make the player rotate smoothly you could use:

 for(int i = 0; i < 45; i++)
            transform.Rotate(Vector3.up, 4, Space.Self);