_ I know little to nothing about C#. That being said, I would prefer if explanations had the code needed to do something and then an explanation of what that does or why that works. _
To get started in Unity I want to make Conway’s game of life, but I don’t know how to make a grid. My idea of how to do so is to create one asset that works as the grid and another that works as a border.
The grid would be made of a 20x20 square that would duplicate itself until the border asset is filled.
My current solution
I would use an if statement that would check one pixel above, below, and beside the square.
If it did not see a grid square in one of those areas, then it would create a grid square that would go through the same procedure.
Once the grid filled the entire area of the boarder, then it would stop running that code.
Asking for code handouts is problematic and you will not learn from reading someone else’s code and putting it in your project, at least not when you’re a beginner.
Grid creation is simple. In Pseudo Code, you would do something like this:
var line : GameObject // in Unity, this would be set to a line sprite or something.
var linedistance : int // the distance between two lines
var gridwidth : int // number of lines to produce on the x-axes
var gridheight : int // number of lines to produce on the y-axes
// it is important to note that the number of boxes produced is as follows:
// boxes in the x direction = gridwidth - 1
// boxes in the y direction = gridheight - 1
// thus, the total number of boxes = (gridwidth - 1) * (gridheight - 1)
Set up the vertical lines:
iterate from 0 to the gridwidth, where x = the current value:
instantiate a new line, set its height to gridheight
place the new line at the position in the x axis: origin + (x * linedistance)
Set up the horizontal lines:
iterate from 0 to the gridheith, where y = the current value:
instantiate a new line, set its height to gridwidth
place the new line at the position in the y axis: origin + (y * linedistance)
And you would use
Rect((linedistance * x) - (linedistance / 2), (linedistance * y) - (linedistance / 2)) to find the center of a square on the grid at position