Created
August 16, 2011 15:04
-
-
Save dbuck/1149310 to your computer and use it in GitHub Desktop.
Return the full hierarchy string of a gameObject, ready for use in GameObject.Find method later
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //Return the full hierarchy string of a gameObject, ready for use in GameObject.Find method later... | |
| static public string GetHierarchy(GameObject g) | |
| { | |
| if (!g || g == null) | |
| { | |
| return ""; | |
| } | |
| string hierarchy = null; | |
| string gname = g.name; | |
| Transform parent = g.transform.parent; | |
| while (parent) | |
| { | |
| hierarchy += "/" + parent.gameObject.name; | |
| parent = parent.parent; | |
| } | |
| string inverse = gname + hierarchy; | |
| string[] arrayh = (string[])inverse.Split(new string[] { "/" }, StringSplitOptions.None); | |
| Array.Reverse(arrayh); | |
| return "/" + string.Join("/", arrayh); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment