- Home /
Set Prefab position when added to scene (Edit mode)
I'm working with an artist who is doing level design for a side scrolling game. When we add a prefab by dragging it into the Scene view from the Project tab, is there a way I can set the Z position automatically?
We work in the Scene view in Ortho back mode, but when we add prefabs to the scene, the Z values are often wacky. I'd like to save a step and have it set it to 0 when first created/added.
Answer by Drakestar · Jul 12, 2012 at 02:28 PM
You can do this by checking for EventType.DragUpdated. Check out this answer for a related solution: http://answers.unity3d.com/questions/29193/editor-dragdrop-override.html
Thanks for the link, with it I made this quick test and it does exactly what I need. Not just when added to the scene, but with any movement in the scene view.
using UnityEngine;
using UnityEditor;
using System.Collections;
[CustomEditor(typeof($$anonymous$$yTestType))]
public class ForcePos : Editor
{
void OnSceneGUI()
{
$$anonymous$$yTestType myTestType = ($$anonymous$$yTestType)target;
myTestType.transform.position = new Vector3(myTestType.transform.position.x, myTestType.transform.position.y, 0);
}
Your answer
Follow this Question
Related Questions
The Script Equivilent of dragging a hierarchy of meshes over a preexisting prefab? 0 Answers
Why do prefabbed meshes go missing whenever I pull an update from Unity Collab? 0 Answers
How Mark Prefab Dirty? 1 Answer
Prefabs shown as blue boxes and not previews 0 Answers
Instantiate prefab in the editor 1 Answer