AnderssonKev

[Editor Script] Move Selected Objects

Nov 13th, 2018
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.01 KB | None | 0 0
  1. using UnityEngine;
  2. using UnityEditor;
  3.  
  4. public class MoveObjectsInDirections : EditorWindow
  5. {
  6.  
  7.     public Vector2 newValues;
  8.  
  9.     [MenuItem("MyScripts/Move Objects")]
  10.     private static void ShowEditor() {
  11.         EditorWindow.GetWindow<MoveObjectsInDirections>(false, "Move Objects");
  12.     }
  13.  
  14.     private void OnGUI() {
  15.         GUILayout.BeginVertical("box");
  16.         EditorGUILayout.HelpBox("All Selected objects in the Hierarchy will be moved.", MessageType.Info);
  17.         if (GUILayout.Button("Move Positions")) {
  18.             if (Selection.transforms.Length > 0) {
  19.                 for (int i = 0; i < Selection.gameObjects.Length; ++i) {
  20.                     Selection.gameObjects[i].transform.localPosition = new Vector2(Selection.gameObjects[i].transform.localPosition.x + newValues.x, Selection.gameObjects[i].transform.localPosition.y + newValues.y);
  21.                 }
  22.             }
  23.         }
  24.         newValues = EditorGUILayout.Vector2Field("Vector", newValues);
  25.         GUILayout.EndVertical();
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment