D
D
Dmitry Demidov2015-11-16 23:28:06
Game development
Dmitry Demidov, 2015-11-16 23:28:06

How to fill the playing field with numbers?

Good evening.
I'm making a game on Unity (I took the off-line roguelike tutorial as a basis).
You need to make a playing field filled with one texture (background) and random numbers on top of it.
I wrote a cycle (altered from the tutorial):

void BoardSetup()
    {
        boardHolder = new GameObject("Board").transform;

        for (int x = 0; x < columns; x++)
        {
            for (int y = 0; y < rows; y++)
            {
                GameObject toInstantiateBackground = snowTile;
                GameObject backgroundInstance = Instantiate(toInstantiateBackground, new Vector3(x, y, 0f), Quaternion.identity) as GameObject;
                backgroundInstance.transform.SetParent(boardHolder);
                GameObject toInstantiateDigit = digitTiles[Random.Range(0, digitTiles.Length)];
                GameObject digitInstance = Instantiate(toInstantiateDigit, new Vector3(x, y, 0f), Quaternion.identity) as GameObject;
                digitInstance.transform.SetParent(backgroundInstance.transform);
            }
        }
    }

I get the following result:
987f4c0c6c0742ae895563dc47166384.PNG
I also tried to set boardHolder as the parent element in the last line, but the result is the same.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
Flabber, 2015-11-17
@ptitca_zu

Are numbers a separate entity? Maybe the layer is not specified.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question