Ok the title is not that clear on what im trying to do.
So i wrote some code instantiating a a grid pattern in a rectaguar area, now im trying to on top of that grid floor to make some walls be instantiated, and i only want a variable percent to be covered.
Now i wrote some code that i thought would be correct. but nothing instantiates on top of my floor.
I thought that the code didnt work because maybe the grid had no child components till after the GameBoard(); had finished, so i used a if statement to delay the Wall(); from initializing till all the grid had been layed…
Would love some suggestions
Have a great day and thanks for any help
public class GameManager : MonoBehaviour
{
[SerializeField]
GameObject cube, cube2, grid, x;
Vector3 position = new Vector3(0f, 0f, 0f);
[SerializeField]
Rect board;
[SerializeField, Range(10f, 80f)]
float percernt;
void Start()
{
GameBoard();
}
private void Update()
{
}
void GameBoard()
{
for(int i=0; i < board.x; i=i+1)
{
position.x = i;
for(int o =0; o< board.y; o = o + 1)
{
position.z = o;
CheckerBoard();
if(i == board.x && o == board.y)
{
Walls();
}
}
}
}
void CheckerBoard()
{
if (position.x%2 == 0)
{
if(position.z%2 == 1)
{
GameObject cubeEvenOdd = Instantiate(cube, position, Quaternion.identity);
cubeEvenOdd.transform.SetParent(grid.transform);
}
else if(position.z % 2 == 0)
{
GameObject cubeEvenEven = Instantiate(cube2, position, Quaternion.identity);
cubeEvenEven.transform.SetParent(grid.transform);
}
}
else if (position.x % 2 == 1)
{
if (position.z % 2 == 0)
{
GameObject cubeOddEven = Instantiate(cube, position, Quaternion.identity);
cubeOddEven.transform.SetParent(grid.transform);
}
else if (position.z % 2 == 1)
{
GameObject cubeOddOdd = Instantiate(cube2, position, Quaternion.identity);
cubeOddOdd.transform.SetParent(grid.transform);
}
}
}
void Walls()
{
for(int j = (x.transform.childCount / grid.transform.childCount*100); j<percernt; j= ((x.transform.childCount+1/grid.transform.childCount)*100))
{
Vector3 pos = new Vector3(position.x, 0.5f, position.z);
GameObject wall = Instantiate(cube, pos, Quaternion.identity);
wall.transform.SetParent(x.transform);
}
}
}