以下の内容はhttps://baba-s.hatenablog.com/entry/2018/01/18/133000より取得しました。


【Unity】GetComponentInChildren で引数の型情報を文字列で渡せるようにする拡張メソッド

ソースコード

using UnityEngine;

public static class GameObjectExt
{
    public static Component GetComponentInChildren( this GameObject self, string type, bool includeInactive )
    {
        var com = self.GetComponent( type );

        if ( com != null ) return com;

        foreach ( var n in self.GetComponentsInChildren<Transform>( includeInactive ) )
        {
            com = n.gameObject.GetComponent( type );

            if ( com != null ) return com;
        }

        return null;
    }
}

使い方

var com = gameObject.GetComponentInChildren( "BoxCollider" );



以上の内容はhttps://baba-s.hatenablog.com/entry/2018/01/18/133000より取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14