実例で学ぶゲーム3D数学 正誤表
http://www.oreilly.co.jp/books/9784873113777/NullReferenceException: Object reference not set to an instance of an objectの出るコンポーネント取得失敗のエラー Unity
- ダメパターン C#
コンポーネントがそもそも失敗してるのに、インデクシングは無理
void Update () { if (!hoges[0]) { // ←これだめ hoges = GetComponents<HogeComponent>(); } else { hoges[0].Bar = "fuga"; } } >|cs| -正解 >|cs| void Update () { if (hoges == null) { hoges = GetComponents<HogeComponent>(); } else { hoges[0].Bar = "fuga"; } }