Skip to content

Instantly share code, notes, and snippets.

@msaroufim
Created December 24, 2020 09:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save msaroufim/fd326ea53b6e781cfa66b1f239728c9c to your computer and use it in GitHub Desktop.
Save msaroufim/fd326ea53b6e781cfa66b1f239728c9c to your computer and use it in GitHub Desktop.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Grid
{
private int width;
private int height;
private float cellSize;
private float cellDistance;
private int[,] gridArray;
//TODO: Cell Distance needs debugging
//Instead of cube use Debug Draw Line and remove cell distance
public Grid(int width, int height, float cellSize, float cellDistance)
{
this.width = width;
this.height = height;
this.cellSize = cellSize;
this.cellDistance = cellDistance;
gridArray = new int[width, height];
for (int x=0; x < gridArray.GetLength(0); x++)
{
for (int y=0; y < gridArray.GetLength(1); y++)
{
//Turn x and y to world coordinates
//GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
//cube.transform.position = GetWorldPosition(x, y);
//cube.transform.localScale *= cellSize;
Debug.DrawLine(GetWorldPosition(x, y), GetWorldPosition(x, y + 1), Color.white, 100f);
Debug.DrawLine(GetWorldPosition(x, y), GetWorldPosition(x + 1, y), Color.white, 100f);
}
Debug.DrawLine(GetWorldPosition(0, height), GetWorldPosition(width, height), Color.white, 100f);
Debug.DrawLine(GetWorldPosition(width, 0), GetWorldPosition(width, height), Color.white, 100f);
}
}
private Vector3 GetWorldPosition(int x, int y)
{
return new Vector3(x, y) * cellSize;
}
public void SetValue(int x, int y, int value)
{
if (x >= 0 && y >= 0 && x < width && y < height)
{
gridArray[x, y] = value;
}
}
}
public class Testing : MonoBehaviour
{
// Start is called before the first frame update
private void Start()
{
Grid grid = new Grid(4, 2, 0.5f, 5f);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment