Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
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:

alt text

alt text

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:

alt text

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
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

151 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple custom editors for same type (or should I re-implement as UI?) 0 Answers

Objects in Custom Editor Resetting on Play 1 Answer

EditorGUILayout.BeginVertical("Box") not filling the inspector 0 Answers

Custom Editor: Array of Structs with elements hidden by toggles 0 Answers

Multiple custom editors for the same type 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges