MoveToOrigin

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
(Enabled undo)
m (Removed "public" class modifier)
Line 15: Line 15:
 
using UnityEngine;
 
using UnityEngine;
  
public class MoveToOrigin {
+
class MoveToOrigin {
 
/// <summary>
 
/// <summary>
 
/// Moves the selected game object(s) to (0, 0, 0).
 
/// Moves the selected game object(s) to (0, 0, 0).

Revision as of 08:01, 7 September 2009

Author: Matthew Miner

Description

Moves the selected GameObject(s) to (0, 0, 0).

Usage

Place the script inside the Editor folder. Select one or more GameObjects and choose GameObject > Move To Origin or press cmd-0 (Mac) / ctrl-0 (Windows). This is functionally equivalent to invoking Reset on a GameObject's transform.

C# - MoveToOrigin.cs

<csharp> using UnityEditor; using UnityEngine;

class MoveToOrigin { /// <summary> /// Moves the selected game object(s) to (0, 0, 0). /// <summary> /// <remarks>Keyboard shortcut: cmd-0 (Mac), ctrl-0 (Windows).</remarks> [MenuItem ("GameObject/Move To Origin %0")] static void MoveToOrigin () { // Move each selected transform to (0, 0, 0) foreach (Transform t in Selection.transforms) { Undo.RegisterUndo(t, "Move " + t.name); t.position = Vector3.zero; Debug.Log("Moving " + t.name + " to origin"); }

   }

/// <summary> /// Validates the "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; } } </csharp>

Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox