Trying to make a series of random walls on my instantiated board

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 :slight_smile:

Have a great day and thanks for any help :slight_smile:

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);
        }


    }

}

I didn’t really read into what your code was doing too much, but on line 90, the really long one, you’re doing division math with ints. I don’t really know what you’re trying to achieve, but I’m guessing that you don’t want it to round after every calculation.

oh god! youre right… @RadRedPanda Hmm, i think an example would work best to explain what i want.

one part of my script makes a game board (lets a ssume a square 10x10)
i want on top of that floor to overlay a percentage (say for eg. 60%) so that i have in a random position on top of the floor walls to make a arena of sorts.