Skip to content

Instantly share code, notes, and snippets.

@paraself
Last active May 23, 2016 06:20
Show Gist options
  • Save paraself/2224a6d836246adc105b6eaf1c8856a1 to your computer and use it in GitHub Desktop.
Save paraself/2224a6d836246adc105b6eaf1c8856a1 to your computer and use it in GitHub Desktop.
Sync 2d Camera between scene view and game view. So whenever you pan your scene view by holding the middle mouse btn, the game view will always match its position to the scene view camera. However scene view's zoom in and out will not be taken into account. The ortho size of the game view camera will remain all the time. This is perfect for maki…
///Sync camera position between scene camera and the rendering camera
//Add [ExecuteInEditorMode] to your monobehaviour and add the following OnRenderObject method as well.
///...
[ExecuteInEditorMode]
//...
void OnRenderObject () {
cam = Camera.current;
if (cam!=null && cam.name == "SceneCamera") {
Vector3 pos = cam.transform.position;
Vector3 _pos = transform.position;
transform.position = new Vector3 (pos.x,pos.y,_pos.z);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment