Question by 
               allaze-eroler · Aug 18, 2018 at 02:59 PM · 
                custom editorcustom-inspectorcustom-editorcustomeditor  
              
 
              EditorGUILayout.Popup with an array of GameObject?
it's been a while i'm trying to figure out why it's not working or to make it work, so far, my goal is to have a dropdown menu which i could select an arrow from up and down... but i'm clueless why it happened... so, here what i have so far:
the door script that i named it as "test":
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class test : MonoBehaviour {
     private bool doorEntered = false; // this bool will activate or not the "teleportation".
     public GameObject[] arrow = new GameObject[2]; // specific arrow of where to go.
 
     void Start()
     {
         arrow[0] = GameObject.FindGameObjectWithTag("arrowDoor").GetComponent<GameObject>();
         arrow[1] = GameObject.FindGameObjectWithTag("arrowDoor").GetComponent<GameObject>();
     }
 
 
     void OnTriggerEnter2D(Collider2D other)
     {
         /*
         this trigger will enable the teleportation feature with the help of the bool when entered.
         */
         if((!doorEntered) && other.tag == "Player")
             {
                 doorEntered = true;
                 Debug.Log("I touched the door");
                 
                 arrow[0].SetActive(true);
                 arrow[1].SetActive(true);
                 Debug.Log("arrow came life!");
             }
     }
         void OnTriggerExit2D(Collider2D other)
         {
             if(other.tag == "Player")
                 {
                     doorEntered = false;
                     Debug.Log("I no longer touched the door");
                 
                     arrow[0].SetActive(false);
                     arrow[1].SetActive(false);
                     Debug.Log("arrow have died!");
                 }
         }
 }
 
               here the doorEditor that i named it as "testEditor":
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEditor;
 
 [CustomEditor(typeof(test))]
 public class testEditor : Editor {
 
         public string[] arrows = new string[] {"arrow Up", "Arrow Down"};
     public int index = 0;
     public override void OnInspectorGUI() {
 
         GUILayout.Space(20);
         serializedObject.Update();
 
         index = EditorGUILayout.Popup(index, arrows);
         serializedObject.ApplyModifiedProperties();
         GUILayout.Space(20);
         base.OnInspectorGUI();
     }
 
     void test()
     {
         switch (index)
         {
             case 0:
                 EditorGUILayout.PropertyField(serializedObject.FindProperty ("arrowDoor"), GUIContent.none, true);
                 break;
 
             case 1:
                 EditorGUILayout.PropertyField(serializedObject.FindProperty ("arrowDoor"), GUIContent.none, true);
                 break;
         }
     }
 }
 
               here the result so far:


unfortunately, it's not working as you could see in the element 0 and element 1 which the script couldn't find the game objects that you can see in that hierarchy:

what i found strange is that i got this message everytime i click "play":
 NullReferenceException: Object reference not set to an instance of an object
 test.Start () (at Assets/Resources/Scripts/test.cs:11)
 
               i suspect that i probably missing something...
 
                 
                script-door3.png 
                (17.6 kB) 
               
 
                
                 
                script-door1.png 
                (31.4 kB) 
               
 
              
               Comment
              
 
               
              Your answer