I got 2 problems with the game,
- I don't know how make my GameObject (snake head) move based in a grid for some reason I don't know it moves freely on the screen.
- The tail keep instantiating above the head not behind... I tried many things and did not work and didn't find an answer in the forum that helps me.
Now I'm back to the begin and looking if someone can help me.
This is the code I use to generate a grid. If anyone could help me with some code, I appreciate it.
public class LevelManagerTest : MonoBehaviour
{
public GameObject tile;
[SerializeField]
private Transform gridParent;
[SerializeField]
public Transform[,] Grid;
private GameObject[,] grid = new GameObject[12, 7];
public float TileSize
{
get { return tile.GetComponent<SpriteRenderer>().sprite.bounds.size.x; }
}
void Start()
{
CreateLevel();
}
private void CreateLevel()
{
Vector3 worldStart = Camera.main.ScreenToWorldPoint(new Vector3(0, Screen.height));
for (int y = 0; y < 7; y++)
{
for (int x = 0; x < 12; x++)
{
PlaceTile(x, y, worldStart);
grid[x, y] = tile;
}
}
}
private void PlaceTile(int x, int y, Vector3 worldStart)
{
// creates a new tile and makes a reference to that file in new tile variable
GameObject newTile = Instantiate(tile, gridParent);
//uses the new tile reference and change the position of the tile
newTile.transform.position = new Vector3(worldStart.x + (TileSize * x), worldStart.y - (TileSize * y), 0);
}
}