Created
July 19, 2011 11:58
-
-
Save AngryAnt/1092083 to your computer and use it in GitHub Desktop.
Simple example of building a Path grid
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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