facebook twitter hatena line email

Unity/Csharp/TryGetComponent

提供: 初心者エンジニアの簡易メモ
移動: 案内検索

TryGetComponentとは

GetComponentで指定したコンポーネントがあるかか確認

サンプル

if (gameObject.TryGetComponent<TextMeshProUGUI>(out var textPro))
{
     textPro.text = "hoge";
}

参考:https://zenn.dev/fuqunaga/articles/61705dbe0f7680

関連

Unity/負荷軽減/GameObjectFind [ショートカット]