Last active
December 29, 2015 02:49
-
-
Save brunomikoski/7603323 to your computer and use it in GitHub Desktop.
Find component upwards.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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