Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Why i don't see the button in the Inspector on debug mode ?

Discussion in 'Scripting' started by Chocolade, Aug 11, 2017.

  1. Chocolade

    Chocolade

    Joined:
    Jun 19, 2013
    Posts:
    916
    Button script:

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4. using UnityEditor;
    5.  
    6. [CustomEditor(typeof(LevelMap))]
    7. public class CustomButton : Editor
    8. {
    9.     public override void OnInspectorGUI()
    10.     {
    11.         LevelMap Generate = (LevelMap)target;
    12.         if (GUILayout.Button("Generate Map"))
    13.         {
    14.             Generate.GenerateNew();
    15.         }
    16.     }
    17. }
    18.  
    And a script that is attached to a empty GameObject the Level Map:

    Code (csharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5. using UnityEngine.UI;
    6.  
    7. [ExecuteInEditMode]
    8. public class LevelMap : MonoBehaviour
    9. {
    10.     public GameObject Node;
    11.     public Vector3 nodeSize;
    12.     public int Rows;
    13.     public int Columns;
    14.     public int mapWidth;
    15.     public int mapHeight;
    16.     public float Spacing = 2.0f;
    17.     public float spawnSpeed = 0;
    18.  
    19.     private void Start()
    20.     {
    21.  
    22.         Generate();
    23.     }
    24.  
    25.     private void Generate()
    26.     {
    27.         for (int x = 0; x < mapWidth; x++)
    28.         {
    29.             for (int z = 0; z < mapHeight; z++)
    30.             {
    31.                 GameObject block = Instantiate(Node, Vector3.zero, Node.transform.rotation) as GameObject;
    32.                 block.transform.parent = transform;
    33.                 block.transform.localPosition = new Vector3(x, 0, z);
    34.             }
    35.         }
    36.     }
    37.  
    38.     public void GenerateNew()
    39.     {
    40.         Generate();
    41.     }
    42. }
    43.  
    One of the problems is that in the Inspector if the mode is normal i see the Generate Button. But i don't see the public variables of Level Map. If i change the mode to Debug then i will see the Level Map public variables but i will not see the button.

    How can i make that i will see the button and the variables at the same mode ? (normal or debug)

    Another problem is how can i make that if generated a new map now if i will change one or more of the variables values in the editor it will effect the GenerateMap in real time ? For example if i change the Spacing variable value if it was for example 2 and i change it to 4 then generate a new map but with spacing 4.

    So the button is like for reset to generate whole new map but changing variables values will effect the current map only.
     
  2. DanielQuick

    DanielQuick

    Joined:
    Dec 31, 2010
    Posts:
    3,137
    Chocolade likes this.
  3. Chocolade

    Chocolade

    Joined:
    Jun 19, 2013
    Posts:
    916
    For the first problem i just added in the button script the line:

    Code (csharp):
    1.  
    2. DrawDefaultInspector();
    3.  
    For the second problem if i'm not using Update and only Start() it will never effect in real time the map if i change any of the public variables values. Then how can i do it ?