Last active
October 19, 2019 14:32
-
-
Save kodai100/95d5012341151c9e30129b812c7d52a7 to your computer and use it in GitHub Desktop.
Find Deep Child as transform.FirstChildOrDefault(trans => trans.name == "name")
This file contains hidden or 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
using System; | |
using UnityEngine; | |
public static class TransformExtension | |
{ | |
public static Transform FirstChildOrDefault(this Transform parent, Func<Transform, bool> query) | |
{ | |
Transform result = null; | |
if (query(parent)) | |
result = parent; | |
if (result != null) | |
return result; | |
foreach (Transform child in parent) | |
{ | |
result = FirstChildOrDefault(child, query); | |
if (result != null) | |
return result; | |
} | |
return null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment