-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFindDescendentTransform.cs
More file actions
34 lines (29 loc) · 886 Bytes
/
Copy pathFindDescendentTransform.cs
File metadata and controls
34 lines (29 loc) · 886 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
public static Transform FindDescendentTransform(Transform searchTransform, string descendantName)
{
Transform result = null;
int childCount = searchTransform.childCount;
for (int i = 0; i < childCount; i++)
{
Transform childTransform = searchTransform.GetChild(i);
// Not it, but has children? Search the children.
if (childTransform.name != descendantName
&& childTransform.childCount > 0)
{
Transform grandchildTransform = FindDescendentTransform(childTransform, descendantName);
if (grandchildTransform == null)
continue;
result = grandchildTransform;
break;
}
// Not it, but has no children? Go on to the next sibling.
else if (childTransform.name != descendantName
&& childTransform.childCount == 0)
{
continue;
}
// Found it.
result = childTransform;
break;
}
return result;
}