Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Help generating a procedural grid

Discussion in 'Scripting' started by klisman, Dec 29, 2015.

  1. klisman

    klisman

    Joined:
    Jun 15, 2015
    Posts:
    31
    Can anyone give me a suggestion of how to represent quad to generate a procedural grid 2d not visible, but that I can use as a reference and store objects in the code?
    I tried using plans objects but it was pretty bad
     
    Last edited: Dec 29, 2015
  2. kietus

    kietus

    Joined:
    Jun 4, 2013
    Posts:
    54
    Hello,

    If the grid is not visible i will say you don't need to render it, each cell of a grid have coordinate (x,y). You can translate a cell position to a world position.
    If you want to render the grid i suppose best solutions are shader side.
    But you can also build your own mesh grid, from quad, in that case, this cool post may help you.
    .
     
  3. klisman

    klisman

    Joined:
    Jun 15, 2015
    Posts:
    31
    Hello,

    My problem is being how to represent/generate the grid without a object.
     
  4. kietus

    kietus

    Joined:
    Jun 4, 2013
    Posts:
    54
    For example
    Code (csharp):
    1.  
    2.   public class GridGenerator
    3.   {
    4.      public Cell[,] CreateGrid(int gridSize)
    5.      {
    6.            Cell[,] grid = new Cell[gridSize, gridSize];
    7.            for (int x = 0; x < gridSize; x++)
    8.            for (int y = 0; y < gridSize; y++)
    9.            {
    10.                  grid[x, y] = new Cell();
    11.             }
    12.             return grid;
    13.       }
    14.   }
    15.  
    16.   public class Cell
    17.   {
    18.   /* cell data and methods */
    19.   }
    20.  
    21.  
     
    klisman likes this.
  5. klisman

    klisman

    Joined:
    Jun 15, 2015
    Posts:
    31
    Got it, thank you!