Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- namespace PUNTutorial
- {
- public static class TransformExtensions {
- public static T FindAnyChild<T>(this Transform trans, string name) where T : Component
- {
- for(int n = 0; n < trans.childCount; n++)
- {
- if(trans.GetChild(n).childCount > 0 )
- {
- var child = trans.GetChild(n).FindAnyChild<Transform>(name);
- if( child != null) return child.GetComponent<T>();
- }
- if(trans.GetChild(n).name == name)
- {
- return trans.GetChild(n).GetComponent<T>();
- }
- }
- return default(T);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment