- Home /
2D Objects not well placed in the grid
Hi I have followed the Board game tutorial and I have been able to place gameobjects. My concern is that the obj are not well placed. it's seems that the grid - cell is too small. Check the pic
I was expected the grid to adapt itslef to the width and height of the prefab.
Any idea. the game is baed on 4 columns / 6 raws.
Merci
What grid? I don't see one there... Where's the logic that's supposed to manage the grid?
Here is the code I use
using UnityEngine; using System; using System.Collections.Generic;
using Random = UnityEngine.Random;
public class Board$$anonymous$$anager : $$anonymous$$onoBehaviour {
[Serializable]
public class Count
{
public int $$anonymous$$imum;
public int maximum;
public Count (int $$anonymous$$, int max)
{
$$anonymous$$imum = $$anonymous$$;
maximum = max;
}
}
public int columns = 4;
public int rows = 6;
// To be replaces by a defined level.
// random is used.
public Count planets = new Count(2,4);
public Count blackholes = new Count(0,2);
public Count teleports = new Count(0,2);
public Count belt = new Count(0,4);
//public GameOjbect shuttleTile;
public GameObject station1Tile;
public GameObject station2Tile;
public GameObject station3Tile;
public GameObject station4Tile;
public GameObject[] planetTile;
public GameObject[] blackholeTile;
public GameObject[] teleportTile;
public GameObject[] asteroidbelt;
private Transform boardHolder;
private List<Vector3> gridPositions = new List<Vector3>();
void InitialiseList(){
gridPositions.Clear ();
for (int x = 1; x < columns; x++) {
for (int y = 1; y < rows ; y++) {
gridPositions.Add (new Vector3 (x, y, 0f));
}
}
}
void BoardSetup(){
boardHolder = new GameObject ("Board").transform;
}
void LayoutPlanetPlace(GameObject[] tileArray){
GameObject tileChoice = tileArray[Random.Range(0, tileArray.Length)];
Instantiate (tileChoice, new Vector3(2, 2, 0f), Quaternion.identity);
tileChoice = tileArray[Random.Range(0, tileArray.Length)];
Instantiate (tileChoice, new Vector3(3, 4, 0f), Quaternion.identity);
tileChoice = tileArray[Random.Range(0, tileArray.Length)];
Instantiate (tileChoice, new Vector3(1, 5, 0f), Quaternion.identity);
}
public void SetupScene(int level){
BoardSetup ();
InitialiseList ();
LayoutPlanetPlace (planetTile);
//Exit
Instantiate (station1Tile, new Vector3(columns-1, rows-1, 0f),Quaternion.identity);
}
}
Answer by goleminthegears · Jan 16, 2017 at 07:37 AM
Is the "Pixel Per Unit" of the sprite the same across all your prefabs for your grid? If not, it could throw off the construction of your grid.