fix: fix issue with GetComponentsInChildrenOnly checking wrong Transform

This commit is contained in:
Oliver Booth 2023-04-10 13:42:12 +01:00
parent 0b5bb074c8
commit a8ebe9c902
No known key found for this signature in database
GPG Key ID: 20BEB9DC87961025
1 changed files with 2 additions and 1 deletions

View File

@ -15,6 +15,7 @@ public static class GameObjectExtensions
/// <returns>An array <typeparamref name="T" /> representing the child components.</returns>
public static T[] GetComponentsInChildrenOnly<T>(this GameObject gameObject)
{
Transform rootTransform = gameObject.transform;
var components = new List<T>(gameObject.GetComponentsInChildren<T>());
for (var index = 0; index < components.Count; index++)
@ -26,7 +27,7 @@ public static class GameObjectExtensions
continue;
}
if (childComponent.transform.parent != gameObject.transform)
if (childComponent.transform == rootTransform)
{
components.RemoveAt(index);
index--;