So, I ended up copy pasting y’alls code from the repos and that fixed the error I was having. I think I had an issue in GridDebugObject.cs. Now i’m having an issue with y’alls code where instead of getting coordniates i’m getting “GridObject”
Here’s my GridDebugObject.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
public class GridDebugObject : MonoBehaviour
{
[SerializeField] private TextMeshPro textMeshPro;
private GridObject gridObject;
public void SetGridObject(GridObject gridObject)
{
this.gridObject = gridObject;
}
private void Update()
{
textMeshPro.text = gridObject.ToString();
}
}
and here is my GridSystem.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GridSystem
{
int width;
int height;
float cellSize;
GridObject[,] gridObjectArray;
public GridSystem(int width, int height, float cellSize)
{
this.width= width;
this.height= height;
this.cellSize = cellSize;
gridObjectArray = new GridObject[width, height];
for (int x = 0; x< width; x++)
{
for (int z=0; z < height; z++)
{
GridPosition gridPosition = new GridPosition(x,z);
gridObjectArray[x,z] = new GridObject(this, gridPosition);
}
}
}
public Vector3 GetWorldPosition(GridPosition gridPosition)
{
return new Vector3(gridPosition.x,0,gridPosition.z) * cellSize;
}
public GridPosition GetGridPosition( Vector3 worldPosition)
{
return new GridPosition(Mathf.RoundToInt(worldPosition.x/cellSize),Mathf.RoundToInt(worldPosition.z/cellSize));
}
public void CreateDebugObjects(Transform debugPrefab)
{
for (int x = 0; x < width; x++)
{
for (int z = 0; z < height; z++)
{
GridPosition gridPosition = new GridPosition(x, z);
Transform debugTransform = GameObject.Instantiate(debugPrefab, GetWorldPosition(gridPosition), Quaternion.identity);
GridDebugObject gridDebugObject = debugTransform.GetComponent<GridDebugObject>();
gridDebugObject.SetGridObject(GetGridObject(gridPosition));
}
}
}
public GridObject GetGridObject(GridPosition gridPosition)
{
return gridObjectArray[gridPosition.x, gridPosition.z];
}
}