i am getting an error in my counsel - OverflowException: Number overflow.
Grid.CreateGrid() (at Assets/Grid.cs:35)
and i can’t figure out why
any help would be appreciated
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Grid : MonoBehaviour
{
//
public LayerMask unwalkableMask;
//size grid will cover
public Vector2 gridWorldSize;
//defines how much space each node covers
public float nodeRadius;
//array for nodes
Node[,] grid;
//
float nodeDiameter;
//
int gridSizeX;
int gridSizeY;
void Start()
{
nodeDiameter = nodeDiameter * 2;
gridSizeX = Mathf.RoundToInt(gridWorldSize.x / nodeDiameter);
gridSizeY = Mathf.RoundToInt(gridWorldSize.y / nodeDiameter);
CreateGrid ();
}
void CreateGrid()
{
grid = new Node[gridSizeX, gridSizeY];
Vector3 worldBottomLeft = transform.position - Vector3.right * gridWorldSize.x / 2 - Vector3.forward * gridWorldSize.y / 2;
for (int x = 0; x < gridSizeX; x++)
{
for (int y = 0; x < gridSizeY; y++)
{
Vector3 worldPoint = worldBottomLeft + Vector3.right * (x * nodeDiameter + nodeRadius) + Vector3.forward * (y * nodeDiameter + nodeRadius);
//collision chec
bool walkable = !(Physics.CheckSphere(worldPoint,nodeRadius,unwalkableMask));
grid [x, y] = new Node (walkable, worldPoint);
}
}
}
void OnDrawGizmos()
{
Gizmos.DrawWireCube (transform.position, new Vector3 (gridWorldSize.x, 1, gridWorldSize.y));
if (grid != null)
{
foreach(Node n in grid)
{
Gizmos.color = (n.walkable) ? Color.white : Color.red;
Gizmos.DrawCube (n.worldPosition, Vector3.one * (nodeDiameter - .1f));
}
}
}
}
