Camera Rotation, Side to top-down view

Hi all, I’m creating a game and I need to use two different view points, I can do this using two cameras and a toggle switch on key press BUT this is like switching a light on and off… I want to do this with a single camera that starts at a set point but follows the player and then with a button press the camera rotates 90 on the X and still looking at the player. the script needs to then work in reverse. I’m new to unity and this is for a uni module however we’re not getting any input on how to use unity.

please help :slight_smile:

Make the camera a child of the observed object, then simply adjust it’s variables: mostlikey just transform.position and transform.rotation, or more simply just the transform.

Example code (that you will most likely copy since it should do EXACTLY what you need it to do):

private Transform firstVP;
private Transform secondVP;

void Start()
{
  firstVP.localPosition = new Vector3(0, 2, 0);
  secondVP.localRotation = Quaternion.Euler(0,-30, 0);
}

void Update()
{
  if(Input.GetKeyDown(KeyCode.V))
    transform = (transform == firstVP ) ? secondVP : firstVP; //not sure if transform supports "==" operator, but here is the reference for the "?" operator in case it confuses you https://msdn.microsoft.com/en-us/library/ty67wk28.aspx
}

Hi sniper43, I’ve had a look at the first code you added on here as its in c# but I cant get it to work there are a few errors which I dont understand.

is there not an easier way to rotate the camera with a button press ?