Munchy2007

PunTutPart4_1

Sep 8th, 2016
8,718
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.58 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. namespace PUNTutorial
  5. {
  6.     public static class TransformExtensions {
  7.  
  8.         public static T FindAnyChild<T>(this Transform trans, string name) where T : Component
  9.         {
  10.             for(int n = 0; n < trans.childCount; n++)
  11.             {
  12.                 if(trans.GetChild(n).childCount > 0 )
  13.                 {
  14.                     var child = trans.GetChild(n).FindAnyChild<Transform>(name);
  15.                     if( child != null) return child.GetComponent<T>();
  16.                 }
  17.  
  18.                 if(trans.GetChild(n).name == name)
  19.                 {
  20.                     return trans.GetChild(n).GetComponent<T>();
  21.                 }
  22.             }
  23.             return default(T);
  24.         }
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment