Quad or Objects grid creation for unity 3D tutorial C#

Difficulty Beginner

Objectives:

  • Create a grid of quad objects in unity 3D
  • modify the grid’s columns and rows count
  • modify the separation between each grid unit in two axis
  • modify the script to be able to use prefabs instead of just quads

Tutorial:

Lets Start Off by creating a C# script: right click in the project window and choose Create->C# Script just like in the image Below

createscript

now lets rename the script: GridScript

Double click the script to open it in monodevelop or your assigned IDE we get something like the script below.

gridscriptempty

now lets start by creating our variables:

Above void Start write the following:

public int NumberOfColumns = 10; // number of columns for the grid
public int NumberOfRows = 10; // number of rows for the grid
public float SeperationValueX = 0.0f; // Distance between each column
public float SeperationValueZ = 0.0f; // Distance between each Row

private float tempSepX = 0; // used to calculate the separation between each column
private float tempSepZ = 0;// used to calculate the separation between each row

Continue reading