I'm trying to get a camera, which uses the Unity character controller, to move to a certain position when a scene is loaded.
For example; in scene1, the camera starts in the centre, however to enter scene 2 the camera muse go through a door on the left of the map.
When the user wants to go back to scene1, from scene2, they should appear on the left side of scene1.
With other scripts I've removed the object from the actual screen, and had it loaded, or instantiated, everytime it is needed. This way, the camera wouldn't need to be moved, just loaded in in the right position.
As a trigger is activated for the scene change I was going with something like this:
Application.LoadLevel ("scene1"); camera.position = (4,20,5);
I know this is wrong, and doesn't work, but I think I'm on the right path ( I hope ).
Could anyone lead me in more of the right direction?
asked Apr 09 '12 at 02:13 PM
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
now for the example player script. this just goes in your normal script.
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 :
You could do this for example, in your camera script:
answered Apr 09 '12 at 02:22 PM