Advertisement
Guest User

Unity Grouping Tool

a guest
Jan 17th, 2020
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. using UnityEditor;
  2. using UnityEngine;
  3.  
  4. public class GroupingTool : MonoBehaviour
  5. {
  6. private const string parentName = "New Parent";
  7.  
  8. [MenuItem("Tools/Group Objects %g")]
  9. private static void GroupObjects()
  10. {
  11. GameObject newParent = new GameObject(parentName);
  12. GameObject[] selection = Selection.gameObjects;
  13.  
  14. foreach(GameObject go in selection)
  15. {
  16. try
  17. {
  18. if (go.transform.parent)
  19. {
  20. continue;
  21. }
  22.  
  23. go.transform.parent = newParent.transform;
  24. }
  25. catch(System.Exception e)
  26. {
  27. Debug.LogError(e.Message);
  28. }
  29. }
  30. }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement