Skip to content

Commit ca5717c

Browse files
Create GetChildComponentByName.cs
1 parent bc82fd5 commit ca5717c

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

GetChildComponentByName.cs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
public static T GetChildComponentByName<T>(string name, GameObject objected, bool caseSensitive = true) where T : Component
2+
{
3+
foreach (T component in objected.GetComponentsInChildren<T>(true))
4+
{
5+
bool comparison = false;
6+
if (!caseSensitive)
7+
comparison = component.gameObject.name.ToLower() == name.ToLower();
8+
else
9+
comparison = component.gameObject.name == name;
10+
if (comparison)
11+
return component;
12+
}
13+
return null;
14+
}

0 commit comments

Comments
 (0)