- Home /
Can scene camera follow the object?
There is a GameOjbect(walker) in My scene,and it move fast when in play mode, And I have to adjust other GameOjects' position around the walker, Can I use a script or something else to control the scene's camera (note:not the camera in play mode).
Can you explain that further? You say 'move fast when in play mode' but then 'not the camera in play mode'. Are you talking about the editor's camera(s)?
Answer by Joshua · Jul 12, 2011 at 04:50 AM
[EDIT: as of Unity 4.3, press Shift-F to lock the scene view to the selected object]
To control the SceneView's camera, you have to use some undocumented (and therefore: officially not supported) methods.
SceneView.lastActiveSceneView.camera.pivot allows you to directly alter the pivot point of the sceneView camera. Using some other standard camera functions this should allow you to do what you want.
Scripts using this need to be in an Editor folder.
If you really want to do this I suggest you decompile UnityEditor.dll and have a look in the SceneView and the Camera classes.
Answer by Lttldude · Oct 21, 2012 at 05:27 AM
I just wrote a script that allows multiple SceneViews to follow a gameobject in edit and play mode. I uploaded it to the Unity3d Wiki: http://wiki.unity3d.com/index.php/SceneViewCameraFollower Check it out.
Answer by yoyo · Apr 08, 2014 at 08:25 PM
I'm not certain when this feature was introduced, but as of Unity 4.3 you can press Shift-F (or double-tap F) to lock the scene camera to the selected object. When the object moves, the scene camera will follow it.
See hotkey documentation.
"double-tap F " works!. The scene view camera follow the selected moving gameobject in the Play mode. By the way why this trick is undocumented. Thanks for the tips.
[Edit] In version Unity 2018.3 use "Shift" + "F" key to lock the camera to moving object. In the future version maybe unity will change back to double tap "F" again, but I'm not sure.
Answer by nbase · Jul 12, 2011 at 03:35 AM
There's a script named 'SmoothFollow' in the standard assets. Add it to the camera and drag the object you want it to follow into the 'Target' slot of the script
Answer by Code_Monkey_Refurbished · Sep 21, 2015 at 06:44 PM
//Allows multiple SceneView cameras in the editor to be setup to follow gameobjects.
//October 2012 - Joshua Berberick
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
[ExecuteInEditMode]
public class SceneViewCameraFollower : MonoBehaviour
{
#if UNITY_EDITOR
public bool on = true;
public bool onlyInPlayMode = false;
public SceneViewFollower[] sceneViewFollowers;
private ArrayList sceneViews;
void LateUpdate()
{
if(sceneViewFollowers != null && sceneViews != null)
{
foreach(SceneViewFollower svf in sceneViewFollowers)
{
if(svf.targetTransform == null) svf.targetTransform = transform;
svf.size = Mathf.Clamp(svf.size, .01f, float.PositiveInfinity);
svf.sceneViewIndex = Mathf.Clamp(svf.sceneViewIndex, 0, sceneViews.Count-1);
}
}
if(Application.isPlaying)
Follow();
}
public void OnDrawGizmos()
{
if(!Application.isPlaying)
Follow();
}
void Follow()
{
sceneViews = UnityEditor.SceneView.sceneViews;
if(sceneViewFollowers == null || !on || sceneViews.Count == 0) return;
foreach(SceneViewFollower svf in sceneViewFollowers)
{
if(!svf.enable) continue;
UnityEditor.SceneView sceneView = (UnityEditor.SceneView) sceneViews[svf.sceneViewIndex];
if(sceneView != null)
{
if((Application.isPlaying && onlyInPlayMode) || !onlyInPlayMode)
{
sceneView.orthographic = svf.orthographic;
sceneView.LookAtDirect(svf.targetTransform.position + svf.positionOffset, (svf.enableFixedRotation) ? Quaternion.Euler(svf.fixedRotation) : svf.targetTransform.rotation, svf.size);
}
}
}
}
[System.Serializable]
public class SceneViewFollower
{
public bool enable;
public Vector3 positionOffset;
public bool enableFixedRotation;
public Vector3 fixedRotation;
public Transform targetTransform;
public float size;
public bool orthographic;
public int sceneViewIndex;
SceneViewFollower()
{
enable = false;
positionOffset = Vector3.zero;
enableFixedRotation = false;
fixedRotation = Vector3.zero;
size = 5;
orthographic = true;
sceneViewIndex = 0;
}
}
#endif
}
Your answer
Follow this Question
Related Questions
How to make camera position relative to a specific target. 1 Answer
Can i load a scene with no Camera 1 Answer
(CLOSED) Plane Failing to Render When Camera is Switched Until Scene is Reloaded?! 0 Answers
How do i remove the gui windows in my scene 1 Answer
turn off selection in the Scene View 0 Answers