Created
August 29, 2024 06:32
-
-
Save inoook/87b897753f1de9296b727226a26d9b0c to your computer and use it in GitHub Desktop.
This file contains 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
// 再帰的に子オブジェクトを検索するメソッド | |
Transform FindChildByName(Transform parent, string childName) | |
{ | |
// 現在の親オブジェクトの全ての子オブジェクトをループ | |
foreach (Transform child in parent) | |
{ | |
// 子オブジェクトの名前が一致する場合、その子オブジェクトを返す | |
if (child.name == childName) | |
{ | |
return child; | |
} | |
// 一致しない場合、さらにその子オブジェクトを探索 | |
Transform result = FindChildByName(child, childName); | |
if (result != null) | |
{ | |
return result; | |
} | |
} | |
// 見つからなかった場合はnullを返す | |
return null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment