Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static GameObject FindObjectWithTag(string tag)
- {
- var objects = FindAllObjects();
- for (int i = 0; i < objects.Length; ++i)
- {
- if (objects[i].CompareTag(tag))
- {
- return objects[i];
- }
- }
- return null;
- }
- public static GameObject FindObjectWithName(string name)
- {
- var objects = FindAllObjects();
- for (int i = 0; i < objects.Length; ++i)
- {
- if (objects[i].name.Equals(name))
- {
- return objects[i];
- }
- }
- return null;
- }
- public static GameObject[] FindAllObjectsWithTag(string tag)
- {
- List<GameObject> result = new List<GameObject>();
- var objects = FindAllObjects();
- for (int i = 0; i < objects.Length; ++i)
- {
- if (objects[i].CompareTag(tag))
- {
- result.Add(objects[i]);
- }
- }
- return result.ToArray();
- }
- public static GameObject[] FindAllObjectsWithName(string name)
- {
- List<GameObject> result = new List<GameObject>();
- var objects = FindAllObjects();
- for (int i = 0; i < objects.Length; ++i)
- {
- if (objects[i].name.Equals(name))
- {
- result.Add(objects[i]);
- }
- }
- return result.ToArray();
- }
- public static GameObject[] FindAllObjects()
- {
- List<GameObject> result = new List<GameObject>();
- var roots = SceneManager.GetActiveScene().GetRootGameObjects();
- result.AddRange(roots);
- for (int j = 0; j < roots.Length; ++j)
- {
- result.AddRange(roots[j].GetAllChilds());
- }
- return result.ToArray();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement