- Home /
Setting position of editor scene camera
I'm trying to move the editor scene camera. I'm able to get the position of the camera easily enough (using a script that extends EditorWindow):
//getting camera position works:
if(Camera.current) {
var sceneCameraPosition = Camera.current.transform.position;
Debug.Log(sceneCameraPosition.ToString());
}
But I don't seem to be able to set the camera position:
//setting camera position FAILS silently:
if(Camera.current) {
var newCameraPos = Vector3(2000,2000,2000);
Camera.current.transform.position = newCameraPos;
}
The script reference docs say that Camera.current is read only, so am I trying to do the impossible here?
Note that if you just want the Scene camera to follow one of your game objects, then just select the object in the Hierarchy and press Shift-F.
Answer by Julien-Lynge · Aug 14, 2011 at 05:38 AM
Thanks NOAA_Julien - that thread is useful. I gave it a try and it does modify the scene camera - so it is possible. However the results aren't what I expected, and it doesn't appear to handle rotation (which I also want to do). But it gives me hope! I'll keep trying.
Glad it worked for you. If this was good enough to solve your immediate question can you mark the answer as accepted so it disappears from the 'Unanswered' list?