Skip to content

Instantly share code, notes, and snippets.

@kodai100
Last active October 19, 2019 14:32
Show Gist options
  • Save kodai100/95d5012341151c9e30129b812c7d52a7 to your computer and use it in GitHub Desktop.
Save kodai100/95d5012341151c9e30129b812c7d52a7 to your computer and use it in GitHub Desktop.
Find Deep Child as transform.FirstChildOrDefault(trans => trans.name == "name")
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