- Home /
Question by
outsidergiant · Mar 24, 2017 at 07:51 PM ·
scripting problemplayerobjectshow to
How to put the player in pandom now busy area of the play field?
I'm new to Unity, trying to make the Bomberman game. I have the field, containing of tiles, concrete walls and brick walls. Now I want to put the player in a free area. But how player controller can know what tile is free and what is not? Here is my BrickWallView code:
public class BrickWallView : MonoBehaviour {
public GameObject brickWall;
public int numberOfWalls;
private float y = 0.5f;
private bool[,] wallMap;
// Use this for initialization
void Start () {
wallMap = new bool[GlobalParameters.numberTilesX, GlobalParameters.numberTilesZ];
PlaceWalls();
}
void PlaceWalls()
{
for (int i = 0; i < numberOfWalls; i++)
{
int x = -1;
int z = -1;
do
{
x = (int)Random.Range(1, GlobalParameters.numberTilesX - 1);
z = (int)Random.Range(1, GlobalParameters.numberTilesZ - 1);
} while (x % 2 == 0 || z % 2 == 0 || wallMap[x, z]);
wallMap[x, z] = true;
Clone(x, z);
}
}
void Clone(int x, int z)
{
GameObject brickWallClone = (GameObject)Instantiate(brickWall, new Vector3(x, y, z), brickWall.transform.rotation);
brickWallClone.SetActive(true);
}
}
Comment