- Home /
Best way to creating random paths in 2D Grid ?
roadTopStartX = Random.Range(5, 10);
roadTopStartY = Random.Range(8, 12);
roadTopLength = Random.Range(4, 9);
for (int i = 0; i < roadTopLength; i++)
{
GameObject tile = GameObject.Find("Tile" + (roadTopStartX + i) + " " + roadTopStartY);
GameObject road = Instantiate(roadPrefab, tile.transform.position, tile.transform.rotation);
road.name = "Road"+ " " + (roadTopStartX + i) + " " + roadTopStartY;
// X kordinatından roadlength kadar sağa çizdir
// randomX 6 : random Y 8 : randomLength 5 6-8 --> 11-8 instantiate road prefabs
roads.Add(road);
}
I create random paths in the 2D grid in this way, but it seems to me that this path is a bad path, do you think, how can I do this as an alternative?
Comment
Your answer
Follow this Question
Related Questions
Creating a 2d array with the Array class 1 Answer
2D Grid Question 0 Answers
Have huge grid data in a way so a 2d range can be pulled effectively? 1 Answer
Highlighting tiles on a hexagonal grid 1 Answer
Block puzzle (1010) help 0 Answers