In this script i create a kind of grid map. But i have some problems.
First it’s not filling the grid. It’s doing only creating the outer width and height and only on two sides. But i want it to be filled like a grid map.
Another problem is that if i put as width and height 4 it should create 4X4 = 16 width height grid. But it’s creating over then 100 objects.
Also how can i make that if i will change the variables values in the editor it will effect the objects in real time ?
Last problem is how can i use the custom button ot generate each time a new grid ? Like reset.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[ExecuteInEditMode]
public class LevelMap : MonoBehaviour
{
public GameObject Node;
public Vector3 nodeSize;
public int mapWidth;
public int mapHeight;
public float Spacing = 2.0f;
// Update is called once per frame
void Update()
{
for (int i = 0; i < mapWidth; i++)
{
Instantiate(Node);
float positionWidth = Spacing * (float)i;
Node.transform.localPosition = new Vector3(positionWidth, 0, 0);
for (int x = 0; x < mapHeight; x++)
{
Instantiate(Node);
float positionHeight = Spacing * (float)x;
Node.transform.localPosition = new Vector3(0, 0, positionHeight);
}
}
}
public void GenerateNew()
{
}
}
And the button script:
using UnityEngine;
using System.Collections;
using UnityEditor;
[CustomEditor(typeof(LevelMap))]
public class customButton : Editor
{
public override void OnInspectorGUI()
{
DrawDefaultInspector();
LevelMap lm = (LevelMap)target;
lm.GenerateNew();
}
}
