Last active
August 29, 2015 14:00
-
-
Save inoook/11241692 to your computer and use it in GitHub Desktop.
GetComponentを上位の階層に対して。SendMessageUpwardsのかわりに。
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 GetComponentUpward<T>(GameObject gObj) where T: Component | |
{ | |
T comp = gObj.GetComponent<T>(); | |
if(comp != null){ | |
return comp; | |
}else{ | |
Transform parentTrans = gObj.transform.parent; | |
if( parentTrans != null){ | |
return GetComponentUpward<T>(parentTrans.gameObject); | |
}else{ | |
return null; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment