Skip to content

Instantly share code, notes, and snippets.

@brunomikoski
Last active December 29, 2015 02:49
Show Gist options
  • Save brunomikoski/7603323 to your computer and use it in GitHub Desktop.
Save brunomikoski/7603323 to your computer and use it in GitHub Desktop.
Find component upwards.
public static T FindComponentUpwards<T>(this Transform pTarget) where T : Component
{
Transform tTransform = pTarget.parent;
while (true)
{
T tComponent = tTransform.GetComponent<T>();
if (tComponent == null)
{
if (tTransform.parent)
{
Transform tParentTransform = tTransform.parent;
tTransform = tParentTransform;
continue;
}
break;
}
return tComponent;
}
return null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment