/* //The intention for this is to fill in all of the tiles not assigned to anything into outer tiles * void CreateOuterTiles() * { * * }*/ //(If we decide to do tilemaps the gameobject array would instead be a tile array void InstantiateFromArray(Sprite[] prefabs, float xCoord, float yCoord, bool isWall = false) { //Create a random index for the array int randomIndex = WeightedRandom.Random(prefabs, randomWeight); //Set the position to instantiate tile Vector3 position = new Vector3(xCoord * tileScale, yCoord * tileScale, 0f); //Create the instance of the tile at the position GameObject a = new GameObject("Tile(" + xCoord + ", " + yCoord + ")"); a.AddComponent <SpriteRenderer>().sprite = prefabs[randomIndex]; a.GetComponent <SpriteRenderer>().material = material; //a.AddComponent<RenderDistance>(); if (isWall) { a.AddComponent <Rigidbody2D>(); a.GetComponent <Rigidbody2D>().bodyType = RigidbodyType2D.Static; a.AddComponent <CompositeCollider2D>(); a.AddComponent <BoxCollider2D>(); a.GetComponent <BoxCollider2D>().offset = new Vector2(0, 0); //Make sure offset and size of collider reflect tile size a.GetComponent <BoxCollider2D>().size = new Vector2(tileScale, tileScale); a.GetComponent <BoxCollider2D>().usedByComposite = true; } a.transform.position = position; a.transform.rotation = Quaternion.identity; a.GetComponent <SpriteRenderer>().sortingOrder = (int)a.transform.position.y * -1; //set the layer to be equal to the y position, but as a negative value tileLocs[(int)xCoord, (int)yCoord] = a.transform.position; //GameObject tileInstance = Instantiate(a, levelData.transform); //Set the tile instance's parent to the level data a.transform.parent = levelData.transform; }