void connectWalls(int[,] maze)
 {
     mazeFile = GameObject.FindGameObjectWithTag(Tags.maze).GetComponent<ImperfectMazeGen>();
     int maxLength = mazeFile.mazeLength * 2 + 1;
     int maxWidth = mazeFile.mazeWidth * 2 + 1;
     int j = (int)this.transform.position.y;
     int i = (int)this.transform.position.x;
     bool isCorner = false;
     
     //You don't need down or left functions because you can clear everything with just up and right.
     if(j + 1 < maxLength && isValidWall(maze,i,(j + 1)))
     {
         createConnectMesh(direction.up, isCorner);
         isCorner = true;
     }
     if(i + 1 < maxWidth && isValidWall(maze,(i + 1),j))
     {
         createConnectMesh(direction.right, isCorner);
     }
 }
 // Use this for initialization
 void Awake()
 {
     mesh = GetComponent<MeshFilter>().mesh;
     mazeFile = GameObject.FindGameObjectWithTag(Tags.maze).GetComponent<ImperfectMazeGen>();
     scale = mazeFile.scale;
     int[,] mazeData = mazeFile.getMaze();
     connectWalls(mazeData);
     if (mesh.vertices.Length > 6)
     {
         gameObject.AddComponent<PolygonCollider2D>();
         PolygonCollider2D polyColl = gameObject.GetComponent<PolygonCollider2D>();
         List<Vector2> verts = new List<Vector2>();
         verts.Add(mesh.vertices[4]);
         verts.Add(mesh.vertices[6]);
         verts.Add(mesh.vertices[7]);
         verts.Add(mesh.vertices[0]);
         verts.Add(mesh.vertices[2]);
         verts.Add(mesh.vertices[3]);
         polyColl.SetPath(0, verts.ToArray());
     }
     else
     {
         mazeFile = GameObject.FindGameObjectWithTag(Tags.maze).GetComponent<ImperfectMazeGen>();
         int maxLength = mazeFile.mazeLength * 2 + 1;
         int maxWidth = mazeFile.mazeWidth * 2 + 1;
         int j = (int)this.transform.position.y;
         int i = (int)this.transform.position.x;
         if (j + 1 < maxLength && isValidWall(mazeData, i, (j + 1)))
         {
             BoxCollider2D collider = gameObject.AddComponent<BoxCollider2D>();
             collider.offset = new Vector2(0, (1 - scale) * ((1 / scale) / 2));
             collider.size = new Vector2(1, (1 / scale));
         }
         else if (i + 1 < maxWidth && isValidWall(mazeData, (i + 1), j))
         {
             BoxCollider2D collider = gameObject.AddComponent<BoxCollider2D>();
             collider.offset = new Vector2((1 - scale) * ((1 / scale) / 2), 0);
             collider.size = new Vector2((1 / scale), 1);
         }
         else
         {
             gameObject.AddComponent<BoxCollider2D>();
         }
     }
 }
 bool isValidWall(int[,] maze,int x,int y)
 {
     mazeFile = GameObject.FindGameObjectWithTag(Tags.maze).GetComponent<ImperfectMazeGen>();
     if(maze[y,x] == 0) // 0 is for wall, 1 is for path
         return true;
     return false;
 }