- Home /
Easy object positioning in the Unity3d editor.
Is there a way to postion new gameobjects in front of the actual sight. Or a way to read the actual sight postion? It's painfully to move new added gameobjects to the actually need place. Every time a add a new gameobject it gets generated somewhere else.
On a side note i am fairly new to unity3d.
Thanks in advance.
Answer by Bunny83 · Jul 22, 2013 at 11:44 AM
Unity does place new Gameobjects right in front of the SceneView. It uses the SceneViews pivot point which is always in the center of the sceneview. How far away the pivot is depends on your last selection (when pressing "F") and how you moved the camera. Zooming the SceneView will change the distance to the pivot. Use this EditorWindow to visualize the pivot point:
// C#
// ShowSceneViewPivot.cs
// Has to be placed in a folder called "Editor"
using UnityEngine;
using UnityEditor;
using System.Collections;
public class ShowSceneViewPivot : EditorWindow
{
[MenuItem("Tools/ShowSceneViewPivot")]
static void Init()
{
GetWindow<ShowSceneViewPivot>();
}
public bool drawCube = true;
public float size = 2.0f;
void OnEnable()
{
SceneView.onSceneGUIDelegate += OnSceneGUI;
}
void OnDisable()
{
SceneView.onSceneGUIDelegate -= OnSceneGUI;
}
void OnSceneGUI(SceneView aView)
{
if (drawCube)
Handles.CubeCap(0,aView.pivot, Quaternion.identity, size);
Repaint();
}
void OnGUI ()
{
GUILayout.Label("Just keep this window open");
drawCube = GUILayout.Toggle(drawCube, "Draw SceneView pivot", "Button");
size = GUILayout.HorizontalSlider(size,0.1f,10.0f);
if (SceneView.lastActiveSceneView != null)
GUILayout.Label("PivotPos: " + SceneView.lastActiveSceneView.pivot);
if (GUI.changed)
{
SceneView.RepaintAll();
}
}
}
Just open the window (Menu->Tools->ShowSceneViewPivot) and keep the window open. You can dock it to another window if you like.
Now you will see a white cube at the SceneViews pivot point. You can change the size with the slider in the window.