Skip to main content
Cleanup
Source Link
DMGregory
  • 140.8k
  • 23
  • 257
  • 401

Change a variable from a random number of GameObjectsrandomly-selected GameObject clones

I'm trying to replicate Minesweeper.

I have this code that spawns a bunch of squares in a grid formation, to make the game board; this leaves me with 100 GameObjectsgame objects all named "square(clone)"

//10x10 grid
yPos = yStart;
for (row = 0; row < 10; row++)
{    xPos = xStart;
    for (column = 0; column < 10; column++)
    {
        newPos = new Vector2(xPos, yPos);
        Instantiate(coolsquare, newPos, Quaternion.identity);
        xPos = xPos + 1f;
    }
    yPos = yPos - 1f;
}
//10x10 grid
yPos = yStart;
for (row = 0; row < 10; row++)
{   
    xPos = xStart;
    for (column = 0; column < 10; column++)
    {
        newPos = new Vector2(xPos, yPos);
        Instantiate(coolsquare, newPos, Quaternion.identity);
        xPos = xPos + 1f;
    }
    yPos = yPos - 1f;
}

theThe squares have this script with a few working idsIDs that tellstell me theytheir row and collumncolumn, and also a status bool

public bool marked = false;
public int rowid, columnid;

filacolum = GameObject.FindGameObjectWithTag("tablerofacil").GetComponent<tablerofacil>();
rowid = filacolum.row;
columnid = filacolum.column;
public bool marked = false;
public int rowid, columnid;

filacolum = GameObject.FindGameObjectWithTag("tablerofacil").GetComponent<tablerofacil>();
rowid = filacolum.row;
columnid = filacolum.column;

So, I want to be able to select a random set of thisthese squares and change their status to "marked = true",.

I tried a few things like tags with "GameObject.FindGameObjectWithTag("square").GetComponent();GameObject.FindGameObjectWithTag("square").GetComponent<squarecode>(); but I can't find a way to access to the variables of multiple clones,. in fact, I can't find a way to change the variables value of any other clone other than the first. I'm pretty new in this gamedev thing so maybe im overcomplicating things from the start so any help is welcomed

I'm triying to replicate minesweeper if it helps lol

Change a variable from a random number of GameObjects clones

I have this code that spawns a bunch of squares in a grid formation, this leaves me with 100 GameObjects all named "square(clone)"

//10x10 grid
yPos = yStart;
for (row = 0; row < 10; row++)
{    xPos = xStart;
    for (column = 0; column < 10; column++)
    {
        newPos = new Vector2(xPos, yPos);
        Instantiate(coolsquare, newPos, Quaternion.identity);
        xPos = xPos + 1f;
    }
    yPos = yPos - 1f;
}

the squares have this script with a few working ids that tells me they row and collumn, and also a status bool

public bool marked = false;
public int rowid, columnid;

filacolum = GameObject.FindGameObjectWithTag("tablerofacil").GetComponent<tablerofacil>();
rowid = filacolum.row;
columnid = filacolum.column;

So, I want to be able to select a random set of this squares and change their status to "marked = true", tried a few things like tags with "GameObject.FindGameObjectWithTag("square").GetComponent(); but can't find a way to access to the variables of multiple clones, in fact, I can't find a way to change the variables value of any other clone other than the first. I'm pretty new in this gamedev thing so maybe im overcomplicating things from the start so any help is welcomed

I'm triying to replicate minesweeper if it helps lol

Change a variable from a number of randomly-selected GameObject clones

I'm trying to replicate Minesweeper.

I have this code that spawns a bunch of squares in a grid formation to make the game board; this leaves me with 100 game objects all named "square(clone)"

//10x10 grid
yPos = yStart;
for (row = 0; row < 10; row++)
{   
    xPos = xStart;
    for (column = 0; column < 10; column++)
    {
        newPos = new Vector2(xPos, yPos);
        Instantiate(coolsquare, newPos, Quaternion.identity);
        xPos = xPos + 1f;
    }
    yPos = yPos - 1f;
}

The squares have this script with a few working IDs that tell me their row and column, and also a status bool

public bool marked = false;
public int rowid, columnid;

filacolum = GameObject.FindGameObjectWithTag("tablerofacil").GetComponent<tablerofacil>();
rowid = filacolum.row;
columnid = filacolum.column;

I want to be able to select a random set of these squares and change their status to "marked = true".

I tried a few things like tags with GameObject.FindGameObjectWithTag("square").GetComponent<squarecode>(); but I can't find a way to access to the variables of multiple clones. in fact, I can't find a way to change the variables value of any other clone other than the first.

added 99 characters in body
Source Link

I have this code that spawns a bunch of squares in a grid formation, this leaves me with 100 GameObjects all named "square(clone)"

//10x10 grid
yPos = yStart;
for (row = 0; row < 10; row++)
{    xPos = xStart;
    for (column = 0; column < 10; column++)
    {
        newPos = new Vector2(xPos, yPos);
        Instantiate(coolsquare, newPos, Quaternion.identity);
        xPos = xPos + 1f;
    }
    yPos = yPos - 1f;
}

the squares have this script with a few working ids that tells me they row and collumn, and also a status bool

public bool marked = false;
public int rowid, columnid;

filacolum = GameObject.FindGameObjectWithTag("tablerofacil").GetComponent<tablerofacil>();
rowid = filacolum.row;
columnid = filacolum.column;

So, I want to be able to select a random set of this squares and change their status to "marked = true", tried a few things like tags with "GameObject.FindGameObjectWithTag("square").GetComponent(); but can't find a way to access to the variables of multiple clones, in fact, I can't find a way to change the variables value of any other clone other than the first. I'm pretty new in this gamedev thing so maybe im overcomplicating things from the start so any help is welcomed

I'm triying to replicate minesweeper if it helps lol

I have this code that spawns a bunch of squares in a grid formation, this leaves me with 100 GameObjects all named "square(clone)"

//10x10 grid
yPos = yStart;
for (row = 0; row < 10; row++)
{    xPos = xStart;
    for (column = 0; column < 10; column++)
    {
        newPos = new Vector2(xPos, yPos);
        Instantiate(coolsquare, newPos, Quaternion.identity);
        xPos = xPos + 1f;
    }
    yPos = yPos - 1f;
}

the squares have this script with a few working ids that tells me they row and collumn, and also a status bool

public bool marked = false;
public int rowid, columnid;

filacolum = GameObject.FindGameObjectWithTag("tablerofacil").GetComponent<tablerofacil>();
rowid = filacolum.row;
columnid = filacolum.column;

So, I want to be able to select a random set of this squares and change their status to "marked = true", tried a few things like tags with "GameObject.FindGameObjectWithTag("square").GetComponent(); but can't find a way to access to the variables of multiple clones. I'm pretty new in this gamedev thing so maybe im overcomplicating things from the start so any help is welcomed

I'm triying to replicate minesweeper if it helps lol

I have this code that spawns a bunch of squares in a grid formation, this leaves me with 100 GameObjects all named "square(clone)"

//10x10 grid
yPos = yStart;
for (row = 0; row < 10; row++)
{    xPos = xStart;
    for (column = 0; column < 10; column++)
    {
        newPos = new Vector2(xPos, yPos);
        Instantiate(coolsquare, newPos, Quaternion.identity);
        xPos = xPos + 1f;
    }
    yPos = yPos - 1f;
}

the squares have this script with a few working ids that tells me they row and collumn, and also a status bool

public bool marked = false;
public int rowid, columnid;

filacolum = GameObject.FindGameObjectWithTag("tablerofacil").GetComponent<tablerofacil>();
rowid = filacolum.row;
columnid = filacolum.column;

So, I want to be able to select a random set of this squares and change their status to "marked = true", tried a few things like tags with "GameObject.FindGameObjectWithTag("square").GetComponent(); but can't find a way to access to the variables of multiple clones, in fact, I can't find a way to change the variables value of any other clone other than the first. I'm pretty new in this gamedev thing so maybe im overcomplicating things from the start so any help is welcomed

I'm triying to replicate minesweeper if it helps lol

Source Link

Change a variable from a random number of GameObjects clones

I have this code that spawns a bunch of squares in a grid formation, this leaves me with 100 GameObjects all named "square(clone)"

//10x10 grid
yPos = yStart;
for (row = 0; row < 10; row++)
{    xPos = xStart;
    for (column = 0; column < 10; column++)
    {
        newPos = new Vector2(xPos, yPos);
        Instantiate(coolsquare, newPos, Quaternion.identity);
        xPos = xPos + 1f;
    }
    yPos = yPos - 1f;
}

the squares have this script with a few working ids that tells me they row and collumn, and also a status bool

public bool marked = false;
public int rowid, columnid;

filacolum = GameObject.FindGameObjectWithTag("tablerofacil").GetComponent<tablerofacil>();
rowid = filacolum.row;
columnid = filacolum.column;

So, I want to be able to select a random set of this squares and change their status to "marked = true", tried a few things like tags with "GameObject.FindGameObjectWithTag("square").GetComponent(); but can't find a way to access to the variables of multiple clones. I'm pretty new in this gamedev thing so maybe im overcomplicating things from the start so any help is welcomed

I'm triying to replicate minesweeper if it helps lol