Hi,
I am creating a new 2d word game such as wordscapes (first game to learn), need advice on few issues/concerns.
I was thinking to store words in a json file for each level and read that, is that the best way to go?
My main issue is laying the square boxes for letters, do I need to design it manually, or is there a way to put tile position, length etc in above json and lay it on level load? if so how would I go about words that start can cross each other as below image?
Appreciate your advice/help.
Thanks

As you are doing this to learn you can probably just lay out your grids by hand - perhaps even copy from wordscapes? Json will be fine for storing the data, for each level just have a list of words with their position on the grid along with length and orientation. With this information you’ll be able to create your UI.
Hi @andymads thanks for reply.
Well learning as well as maybe releasing it to users if it gets to that level 
Got couple of questions:
-
If I drive the grid from json file, how would I go about it to do above example?
-
Also by grid do you mean UI grid component or just boxes in grid?
-
“copy from wordscapes?” - do I need to decompile or you mean literary copy what I see 
-
Also is there another way apart from json file?
Thanks
The problem here is that I don’t know what level of help you need. Are you a rank novice in Unity and game development in general? You’re asking about json. Do you know what json is and how to serialise an object to json, and deserialise json back to an object? Do you know what I mean by object? Do you know any other way to get data into your game? Let’s say that you get the data into your game - do you have an idea how you’re going to draw the level using Unity UI?
ah ok so, I am new to Unity have gone though couple of tutorials and have a good knowledge, I can layout UI and draw UI manually or by code.
As for c# have got 10 years experience, so I know about json/object how to convert.
The part I want to know more about is if I want to drive the UI from json, and by UI I mean the letter boxes, how would I layout a complex grid like the image above - is there a benefit of doing it in json or doing each level manually by hand? apart from less work in future.
Also is it normally good idea to store level info in Json in unity or does unity provide any other form of resource location
Thanks
The way I layout the crosswords in the games I’ve done is to use a GridLayoutGroup as a parent and add a combination of invisible objects (simply a RectTransform) and visible objects (the letter boxes).
I like using json as it’s easy to deserialise straight into an object with mimimum effort. For the crosswords in my games though I have json exported from another tool, which I then import into Unity and create scriptable objects containing all the data. At runtime the scriptable objects are used to construct the puzzles.
I see no reason to manually layout anything unless it’s just a handful of levels for a learning experience.
From what you are saying, I get that you are just lost in how to implement things on unity. I recommend a grid MonoBehaviour to set the grid size (x,y) and manage the actual world positions of where the boxes should go.
For the boxes, you should have a prefab with a BoxLetter mono in charge of holding the info about what letter is it, changing the sprite or text to reflect it, and talking to the grid to position itself, etc.
Then you would need a levelLoader mono in charge of parsing the json and instantiating the prefabs, GetComponent of the last created box prefab and setting it according to the parsed json data.
Brilliant, thank you @andymads & @whileBreak … I am very clear now will come back if further issues 
for starters, set the parent before you change the position and scale.
And for seconds, this should be the formula for the positions:
float x = col * tileSize + col * tileDistance - ( _grid.GetLenght(1) * tileSize + tileDistance * (_grid.GetLenght(1)-1))/2f;
float y = row * tileSize + row * tileDistance - ( _grid.GetLenght(0) * tileSize + tileDistance * (_grid.GetLenght(0)-1))/2f;
@whileBreak thanks will try and get back to you
@whileBreak I have used your calculations got few issues:
private float tileDistance = 1f;
private float tileSize = 1f;
private void CreateGrid()
{
for (int x = 0; x < _grid.GetLength(0); x++)
{
for (int y = 0; y < _grid.GetLength(1); y++)
{
GameObject letterBox = Instantiate(LetterBoxPrefab);
letterBox.name = "letter_box_" + x + "_" + y;
letterBox.transform.SetParent(transform, false);
//letterBox.transform.localScale = new Vector2(1, 1) * (tileSize - 1);//set tile size
//letterBox.transform.position = GetScreenPointFromLevelIndices(x, y); //place in scene based on level indices
float xAxis = y * tileSize + y * tileDistance - (_grid.GetLength(1) * tileSize + tileDistance * (_grid.GetLength(1) - 1)) / 2f;
float yAxis = x * tileSize + x * tileDistance - (_grid.GetLength(0) * tileSize + tileDistance * (_grid.GetLength(0) - 1)) / 2f;
letterBox.transform.position = new Vector2(xAxis, yAxis);
}
}
}
- The Y axis of grid is not according to panel seems to start from middle of panel, see in picture(grid.png) the light blue is the panel which is set to middle center.
- I cannot see these boxes in design mode - see picture(design mode.png).
- Also can you please explain how you came with the calculation - sorry my math is not good and am beginner in unity

Oh I see, well put the grid inside the panel, then it will take the center of the panel.
The calculations are kind of self explanatory. I’ll explain just X axis.
you need to move the tile according to the space taken by the other tiles plus the space taken by the space in between tiles (one less than the number of tiles). For tile 0 it should be 0, since no other tile is before it. So
float x = col * tileSize + col * tileDistance;
Checks out. Also if tile is 1, you will get the size of the tile 0 plus a “in between” value.
The other part is just offsetting the value according to the size of the grid, tile size * number of tiles
_grid.GetLength(1) * tileSize
And the space for the in betweens (1 less than the tiles, count them)
tileDistance * (_grid.GetLenght(1)-1)
And the divide them by 2 to offset just by half the total grid size, so the grid gets centered.
( _grid.GetLenght(1) * tileSize + tileDistance * (_grid.GetLenght(1)-1)) / 2f
@whileBreak thanks for explanation, cannot put the grid inside panel…it is a multi dimensional-array gameobject and cannot get transform property.
I have attached the script to panel.
Oh great, that works too. What I meant was to put the grid (game object) inside the panel on the hirarchy, that way it would take the panel’s center as the origin.
@whileBreak the grid looks good finally 
Am struggling to create the boxletter, so in UI editor I am creating an empty object then add canvas then text the text is not showing…any suggestions?
It could be the size, or the position of the text. are you adding the canvas inside another canvas? that could also be it. Or even the color
Thanks @whileBreak one last question hopefully 
right now am reading letter positions from json like so : “PositionOnGrid”: “1,0;1,1;1,2” then parse it by simicolon and then parse it by comma which works fine.
To save me from doing all above I thought to convert this to json object and let unity’s json deserializer populate my class, like below:
PositionOnGrid :
{
“0”: [1, 0],
“1”: [1, 1],
“2”: [1, 2]
}
But as the size of letters could be different how am I gonna resolve this on the corresponding class ? I thought about dynamic property but no joy.
if the field “0” “1” “2” are your letters then you need to aproach them from a different perspective. Your letters are an array, so treat them like so.
{
“letters”: [
{
“x” : “1”,
“y” : “0”
},
{
“x” : “1”,
“y” : “1”
},
{
“x” : “1”,
“y” : “2”
}
]
}
// Structs for the native json parser from unity, just the concept not the actual implementation
struct LetterContainer
{
public Letter[] letters;
}
public Letter
{
public int x;
public int y;
}
void FunctionParser()
{
// I don't remember the actual json parser library or function, sorry
// Edit found it! already corrected
LetterContainer container = JsonUtility.FromJson<LetterContainer>(jsonString);
}