- Home /
How to focus on an object in the Scene View during run time using a script
I want to draw a line from my object at run time (debug.DrawLine). To see this line, I should use the scene view, let's say that I split my monitor, so it show the GameView and the SceneView at the same time, the problem is that in the game view, I want to move the object (using the arrow keys) and I want to see the line in the scene view, but the object is moving fast, so it will be out of view in the SceneView, and I find myself pressing f rapidity in the SceneView to bring the object into the view again. is there any way to make this happen in the script ?
Answer by anisabboud · Mar 16, 2015 at 07:56 PM
To lock the view to a game object, select it in the Hierarchy and press Shift+F.
(Alternatively, you can select Edit → Lock View to Selected
.)
Answer by Lttldude · Apr 19, 2012 at 12:37 PM
Put this in the update function of the gameobject that you want to keep in view.
SceneView.lastActiveSceneView.FrameSelected();
Disclaimer: Undocumented API is not officially supported and subject to change at anytime.
Good luck.
Sorry, not working, there is no SceneView class in my version of Unity (3.5.1f2)
It is undocumented API, which means it won't show up in your ID$$anonymous$$ You just type it exactly as shown.
Just like to add that this is of course a function from the UnityEditor namespace! This can only be used in an editor script.
If you want to use it in a runtime script you have to make sure it doesn't go into the build:
#if UNITY_EDITOR
UnityEditor.SceneView.lastActiveSceneView.FrameSelected();
#endif
Wow it is working ! thanks ! but why it is not documented ? it is very handy, thanks for you...
by the way, is there any method to control the zoo$$anonymous$$g in the SceneView ?