Skip to content

Instantly share code, notes, and snippets.

@mminer
Last active July 5, 2018 09:59
Show Gist options
  • Select an option

  • Save mminer/3759189 to your computer and use it in GitHub Desktop.

Select an option

Save mminer/3759189 to your computer and use it in GitHub Desktop.
Unity editor script that provides a shortcut to move the selected game object to the origin (0, 0, 0).
using UnityEditor;
using UnityEngine;
class MoveToOrigin
{
/// <summary>
/// Moves selected game object(s) to (0, 0, 0).
/// <summary>
/// <remarks>Keyboard shortcut: shift-cmd-0 (Mac), shift-ctrl-0 (Windows).</remarks>
[MenuItem ("GameObject/Move To Origin #%0")]
static void MenuMoveToOrigin ()
{
foreach (var t in Selection.transforms) {
Undo.RecordObject(t, "Move " + t.name);
t.position = Vector3.zero;
Debug.Log("Moving " + t.name + " to origin.");
}
}
/// <summary>
/// Validates "Move To Origin" menu item.
/// </summary>
/// <remarks>The menu item will be disabled if no transform is selected.</remarks>
[MenuItem ("GameObject/Move To Origin %0", true)]
static bool ValidateMoveToOrigin ()
{
return Selection.activeTransform != null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment