While @gregzo method works, I am going to expand on it.
If you have more than one door the player can enter the scene from, you may want to set the position and rotation of the camera for the next scene based on what door you are walking through.
I shall step out the methods.
Start with making a script for the camera. The name of this script is important to make the second script work. Call it → CamSetLocation.js
// Main Camera Script
#pragma strict
public var CamNextLocation : Vector3;
public var CamNextRotation : Quaternion;
function Start()
{
DontDestroyOnLoad(this.gameObject);
}
public function OnLevelWasLoaded()
{
transform.position = CamNextLocation;
transform.rotation = CamNextRotation;
}
now for the example player script. this just goes in your normal script.
// Player Script
#pragma strict
var camScript : CamSetLocation; // CamSetLocation is the name of the script on the Main Camera
function Awake()
{
// load camScript with CamSetLocation.js (the script on the Main Camera)
camScript = GameObject.Find("Main Camera").GetComponent(CamSetLocation);
// move the camera
camScript.OnLevelWasLoaded();
}
function NextLevel()
{
// set the camera location before loading the new scene
camScript.CamNextLocation = Vector3(5, 1, -2);
camScript.CamNextRotation = Quaternion.Euler(35, 155, 0);
// Application.LoadLevel ("NextLevel");
}
Steps :
The player script finds the Main Camera and stores a reference to that script. Then you can change the position and rotation variables before you leave the scene (walk through a door).
So when you walk through a door, run the function NextLevel(), telling the camera it’s next position and rotation. Then load the new scene.
In the new scene, the player script function Awake() calls the camera script function OnLevelWasLoaded() , to move the camera to the position and rotation set on leaving the last scene.
OR … (and this is a separate answer, just an example on directly moving the camera without finding any scripts)
if the player knows where it is supposed to be in the new scene, you can directly tell the camera to move :
var TellCamNextLocation : Vector3 = Vector3(1, 2, 3);
function MoveCamera()
{
// directly move the Main Camera
Camera.mainCamera.transform.position = TellCamNextLocation;
}