Jump to content

I have an array of tiles that I need the bottom, and top ones to instantiate in a different location, because the tiles are rectangles and I dont want a bunch of space between the tiles and the other tiles.

using UnityEngine;
using System.Collections;

public class Tiles : MonoBehaviour {

    int mapsizeY = 3;
    int mapsizeX = 3;

    public TileType[] tiletypes;

    int[,] tiles;

    void Start()
    {
        tiles = new int[mapsizeX, mapsizeY];

        for (int x = 0; x < mapsizeX; x++)
        {
            for (int y = 0; y < mapsizeX; y++)
            {
                tiles[x, y] = 0;
            }
        }
        GenerateMapVisuals();
    }
    void GenerateMapVisuals()
    {
        tiles = new int[mapsizeX, mapsizeY];

        for (int x = 0; x < mapsizeX; x++)
        {
            for (int y = 0; y < mapsizeX; y++)
            {
                TileType tt = tiletypes[tiles[x, y]];

                Instantiate(tt.tileprefab, new Vector3(x, y, 0), Quaternion.identity);
            }
        }
    }
    // Update is called once per frame
    void Update () {
	
	}
}

 

Link to comment
https://linustechtips.com/topic/680532-how-to-instantiate-objects-offset-unity/
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×