1
0
mirror of https://github.com/oliverbooth/X10D synced 2024-11-22 19:28:48 +00:00

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

View File

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