Skip to content

Instantly share code, notes, and snippets.

@inoook
Last active August 29, 2015 14:00
Show Gist options
  • Save inoook/11241692 to your computer and use it in GitHub Desktop.
Save inoook/11241692 to your computer and use it in GitHub Desktop.
GetComponentを上位の階層に対して。SendMessageUpwardsのかわりに。
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