Skip to content

Instantly share code, notes, and snippets.

@AngryAnt
Created July 19, 2011 11:58
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 AngryAnt/1092083 to your computer and use it in GitHub Desktop.
Save AngryAnt/1092083 to your computer and use it in GitHub Desktop.
Simple example of building a Path grid
// Given: float width, float height, float xSpacing, float ySpacing, Vector3 gridStart
Waypoint[] points = new Waypoint[width * height];
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
points[y * width + x] = new GameObject (string.Format ("Grid-{0}-{1}", x, y), typeof (Waypoint)).GetComponent<Waypoint> ();
points[y * width + x].transform.position = gridStart + Vector3.z * ySpacing + Vector3.x * xSpacing;
}
}
for (int y = 0; y < height - 1; y++)
{
for (int x = 0; x < width - 1; x++)
{
new Connection (points[y * width + x], points[y * width + x + 1]);
new Connection (points[y * width + x], points[(y + 1) * width + x]);
// TODO: Setup of connection data
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment