I am new to Unity. I have a simple game object with one script attached to it and then another script to add a button which will call the function within the script attached to the game object. My problem is I want to have two editable fields height
and width
but if the custom editor is added to the game object then those public fields no longer display in the inspector window...Not sure why?
WorldGenerator.cs:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class WorldGenerator : MonoBehaviour {
public int height;
public int width;
public void RunWorldGeneration()
{
Generate worldGenerator = new Generate();
float[,] world = worldGenerator.GenerateWorld(width, height);
}
}
WorldGeneratorEditor.cs:
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
[CustomEditor(typeof(WorldGenerator))] // If I comment this out the public variablbes show
// If it is uncommented, then just the button with "Generate" text shows
public class MapGeneratorEditor : Editor
{
public override void OnInspectorGUI()
{
WorldGenerator worldGen = (WorldGenerator)target;
if (GUILayout.Button("Generate"))
{
worldGen.RunWorldGeneration();
};
}
}