Last active
April 9, 2026 13:56
-
-
Save adamski11/ff3bc5e77526be72b52fb1ee752cc082 to your computer and use it in GitHub Desktop.
Get Active Sibling Index - Use this script to create the extension method GetActiveSiblingIndex which allows you to find the sibling index whilst ignoring inactive siblings. Useful for animations that are meant to run in sequence, but have unusual delays caused by inactive sibling changing the numbers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System.Collections; | |
| using System.Collections.Generic; | |
| using UnityEngine; | |
| public static class GetActiveSiblingIndexScript { | |
| public static int GetActiveSiblingIndex(this Transform transform) | |
| { | |
| int index = 0; | |
| for (int i = 0; i < transform.parent.childCount; i++) | |
| { | |
| Transform nextChild = transform.parent.GetChild(i); | |
| if (!nextChild.gameObject.activeSelf) | |
| continue; | |
| else if (nextChild == transform) | |
| return index; | |
| else | |
| index++; | |
| } | |
| return index; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment