(https://teratail.com/questions/62810)
からの派生なのですが、うえのURLから、回答を頂き、以下のソースを書いたところ以下のエラーが出ました
C#
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4 5public class Doorscript : MonoBehaviour { 6 7 // Use this for initialization 8 void Start () { 9 10 } 11 12 // Update is called once per frame 13 void OnTriggerEnter ( Collider other ) { 14 if (transform.Find ("Key").gameObject.activeSelf) 15 { 16 GameObject.Find("Doors").transform.Find("DoorA").gameObject.SetActive(false); 17 } 18 } 19}
これを実行すると、
NullReferenceException: Object reference not set to an instance of an object
Doorscript.OnTriggerEnter (UnityEngine.Collider other) (at Assets/Script/Doorscript.cs:14)
と出てしまいます。
どなたか解決方法を教えて下さい。
追記
上記のソースを以下のソースにかえてみましたが、変化なしでした。
C#
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4 5public class Doorscript : MonoBehaviour { 6 7 // Use this for initialization 8 void Start () { 9 10 } 11 12 // Update is called once per frame 13 void OnTriggerEnter ( Collider other ) { 14 if (GameObject.Find ("Key").gameObject.activeSelf) 15 { 16 GameObject.Find("DoorA").gameObject.SetActive(false); 17 } 18 } 19}
ちなみに、このスクリプトは、まず違うスクリプトでプレイヤーと衝突したら、"Key"をfalseにして、そのKeyがfalseの場合に、ドアとぶつかったら、そのドアをfalseにする。
といったのもです。
追記終了
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。