- Home /
Random Grid Genaration with walls C#
Hi everyone, sorry for my bad english. I have a problem making borders of my grid with this script i can create a grid
using UnityEngine;
using System.Collections;
public class array : MonoBehaviour {
public GameObject Tile_Walk;
public GameObject Tile_Wall;
public GameObject PG;
public int GridX;
public int GridY;
// Use this for initialization
public int PGX;
public int PGY;
int i;
int j;
void Start() {
PGX = Random.Range(1, (GridX - 1));
PGY = Random.Range(1, (GridY - 1));
for (i = 0; i < GridX; i++)
{
for (j = 0; j < GridY; j++)
{
if ((j!=0) &&(i!=0)&& (j != GridY) && (i != GridX)) {
Instantiate(Tile_Walk, new Vector3(i, j, 0), Quaternion.identity);
}
else
Instantiate(Tile_Wall, new Vector3(i, j, 0), Quaternion.identity);
}
}
Instantiate(PG, new Vector3(PGX, PGY, -1), Quaternion.identity);
}
// Update is called once per frame
void Update () {
}
}
but it look like this...
how can i make Walls in all borders?
edit:prblem solved
using UnityEngine;
using System.Collections;
public class array : MonoBehaviour {
public GameObject Tile_Walk;
public GameObject Tile_Wall;
public GameObject PG;
public int GridX;
public int GridY;
// Use this for initialization
public int PGX;
public int PGY;
int i;
int j;
void Start() {
PGX = Random.Range(1, (GridX - 1));
PGY = Random.Range(1, (GridY - 1));
for (i = 0; i < GridX; i++)
{
for (j = 0; j < GridY; j++)
{
if ((j!=0) &&(i!=0)&& (j != GridY-1) && (i != GridX-1)) {
Instantiate(Tile_Walk, new Vector3(i, j, 0), Quaternion.identity);
}
else
Instantiate(Tile_Wall, new Vector3(i, j, 0), Quaternion.identity);
}
}
Instantiate(PG, new Vector3(PGX, PGY, -1), Quaternion.identity);
}
// Update is called once per frame
void Update () {
}
}
capture.png
(12.3 kB)
Comment
Your answer
Follow this Question
Related Questions
How can I accomplish Tetris rotations with 2D arrays? 1 Answer
Error while spawning multiple objects 1 Answer
Path Finding using 2 dimensional array 1 Answer
Switch Players during play 2 Answers