In the top of the script:
public int mapWidth = 10;
public int mapHeight = 10;
Then in a loop:
private void Generate()
{
if (objects.Count > 0)
objects = new List<GameObject>();
if (Node == null)
Node = GameObject.FindGameObjectWithTag("Main Node");
for (int x = 0; x < mapWidth; x++)
{
float positionWidth = Spacing * (float)x;
for (int z = 0; z < mapHeight; z++)
{
float positionWidth1 = Spacing * (float)z;
GameObject block = Instantiate(Node, Vector3.zero, Node.transform.rotation) as GameObject;
block.transform.parent = transform;
block.transform.localPosition = new Vector3(positionWidth, 0, positionWidth1);
block.transform.localScale = new Vector3(nodeScale.x, nodeScale.y, nodeScale.z);
block.tag = "NodeDestroyable";
objects.Add(block);
}
}
}
But i want to add two rules:
The user will not be able to enter as int numbers 2 or less. So mapWidth or/and mapHeight will never be 2 both or one of them and also the numbers in both int variables should be the same like 7 and 7 or 10 and 10 but not 8 and 9 or 67 and 4.
If the user enter this numbers prevent from him to generate.
And i have a button that i click to Generate so i need also to take care the button maybe somehow to enable/disable the button: This is the button class:
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
[CustomEditor(typeof(Generator))]
public class GenerateButton : Editor
{
public override void OnInspectorGUI()
{
Generator Generate = (Generator)target;
if (GUILayout.Button("Generate New Map"))
{
Generate.GenerateNew();
}
DrawDefaultInspector();
if (GUILayout.Button("Destroy Nodes"))
{
Generate.DestroyNodes();
}
}
}
The idea is to prevent from the user to enter this values and also to prevent the user from clicking the button if the values are wrong.
About enable/disable the button i can’t find any way to do it.
I can disable the whole guilayout but it will disable also the other variables i want to enable/disable only the button.