[ Web Proxy ]
URL:
Viewing: https://docs.unity3d.com/ScriptReference/Selection.GetTransforms.html [Back]  [Original]

Unity - Scripting API: Selection.GetTransforms
Version: Unity 6.5 (6000.5)
    • Supported
    • Legacy
    LanguageEnglish
    • C#

    Selection.GetTransforms

    Suggest a change

    Success!

    Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

    Close

    Submission failed

    For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

    Close
    Your name Your email Suggestion* Submit suggestion

    Cancel

    Declaration

    public static Transform[] GetTransforms(SelectionMode mode);

    Parameters

    Parameter Description
    mode Options for refining the selection. Refer to SelectionMode for the available modes.

    Returns

    Transform[] The transforms of the selected objects determined by the mode.

    Description

    Retrieves the transforms of selected objects.

    Retrieves the transform of the current Editor selection after applying the provided SelectionMode flags. You can use this to iterate through relevant scene objects (such as editable transforms) and perform batch operations on them.

    using UnityEngine;
    using UnityEditor;

    class CreateParentForTransforms : ScriptableObject { [MenuItem("Example/Create Parent For Selection _p")] static void MenuInsertParent() { Transform[] selection = Selection.GetTransforms( SelectionMode.TopLevel | SelectionMode.Editable); GameObject newParent = new GameObject("Parent");

    foreach (Transform t in selection) { t.parent = newParent.transform; } }

    // Disable the menu if there is nothing selected [MenuItem("Example/Create Parent For Selection _p", true)] static bool ValidateSelection() { return Selection.activeGameObject != null; } }

    Web Proxy Viewer  |  New URL  |  Original Page