Rotating the camera over a period of time

Hi all!

I’m currently working on a small game where I would like to rotate the camera depending on the state of one of my variables. The game has 4 walls, here’s a screenshot, all tagged according to which wall they are. When the player hits one of the walls the gravity changes to make it so that the wall acts as the ground in which the gravity pushes down on, I’d like to rotate the camera to reflect this.

The variable currently responsible for change in gravity is gravityState, when this = 1 the gravity acts down, 2 = left, 3 = up, 4= right. I’ve got no idea how to code a change in the camera’s rotation so that it not only reflects gravityState, but also have the rotation happen over a small period of time.

Any help with the code would be greatly appreciated.

You have to access the camera’s transform in order to manipulate it’s position, angle etc.

To do something each frame you need to place the code in the update so it will look something like this:

void Update()
{
     transform.Rotate(Vector3.forward, 15.0f * Time.deltaTime);
}

(This piece of code assumes that the script is on the camera’s game object)
If you are unsure how to access camera from another script etc, let me know.