Selection.GetFilteredstatic function GetFiltered (type : Type, mode : SelectionMode) : Object[]DescriptionReturns the current selection filtered by type and mode. For a selected GameObject that has multiple Components of type, only the first one will be included in the results. // MenuItem adds a menu item in the GameObject menu
// and executes the following function when clicked @MenuItem ("GameObject/Apply values") static function ApplyHardcodedValues () { // Get all selected game objects that we are allowed to modify! var gos = Selection.GetFiltered(GameObject, SelectionMode.Editable); // Change the values of all for (var go in gos) { // Change the layer of the game object to 2 go.layer = 2; } // Get all selected rigid bodies that we are allowed to modify! var bodies = Selection.GetFiltered(Rigidbody, SelectionMode.Editable); // Change the values of all for (var body in bodies) { // Change the layer of the game object to 2 body.mass = 5; } } |
