Skip to content

Instantly share code, notes, and snippets.

@kimsama
Created March 29, 2014 02:10
Show Gist options
  • Select an option

  • Save kimsama/9847077 to your computer and use it in GitHub Desktop.

Select an option

Save kimsama/9847077 to your computer and use it in GitHub Desktop.
extending method to already exist class
public static class TransformHelper
{
public static Transform GetChild(this Transform self, string name)
{
Transform t = null;
if(name != "")
t = self.Find(name);
if(t == null)
t = self;
return t;
}
public static Transform FindChildByName(this Transform self, string childname)
{
Transform found = null;
if (self.name == childname)
return self.transform;
foreach (Transform child in self)
{
found = child.FindChildByName(childname);
if (found)
{
return found;
}
}
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment